【问题标题】:how to do countplot of several excel sheet of same excel file using python?如何使用python对同一excel文件的几个excel表进行countplot?
【发布时间】:2020-11-30 06:26:50
【问题描述】:

https://github.com/mehenaaz/Employee_Attrition_Analysis/blob/main/Emp1.xlsx 我有一个 excel 文件,其中包含两个不同的工作表,名为“现有员工”和“左员工”。每个都有多个相同的列名。我需要使用python计算同一个excel文件的几个excel表。就像我想在 countplot 中显示“现有员工”和“离开员工”之间的满意度比较。我该怎么做? 我想要这样的结果:countplot

【问题讨论】:

    标签: python excel pandas plot count


    【解决方案1】:

    这应该让你开始:

    import matplotlib.pyplot as plt
    import pandas as pd
    
    filename = 'Emp1.xlsx'
    
    sheet = 'current_employee'
    df1 = pd.read_excel(filename,sheet_name=sheet)
    df1.boxplot(column='satisfaction_level')
    plt.title(sheet)
    plt.show()
    
    sheet = 'left_employee'
    df2 = pd.read_excel(filename,sheet_name=sheet)
    df2.boxplot(column='satisfaction_level')
    plt.title(sheet)
    plt.show()
    


    编辑:为子图格式化

    import matplotlib.pyplot as plt
    import pandas as pd
    
    filename = 'Emp1.xlsx'
    
    fig, axes = plt.subplots(nrows=1, ncols=2, sharey=True)
    
    sheet = 'current_employee'
    df1 = pd.read_excel(filename,sheet_name=sheet)
    ax1 = df1.boxplot(column='satisfaction_level',ax=axes[0])
    ax1.title.set_text(sheet)
    
    sheet = 'left_employee'
    df2 = pd.read_excel(filename,sheet_name=sheet)
    ax2 = df2.boxplot(column='satisfaction_level',ax=axes[1])
    ax2.title.set_text(sheet)
    plt.show()
    

    【讨论】:

    • 我想要一张图中的结果...比较两张纸上的两个相同的列。
    猜你喜欢
    • 1970-01-01
    • 2020-11-20
    • 2021-03-16
    • 2023-04-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-03-18
    相关资源
    最近更新 更多