import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
df = pd.read_excel(r'成绩表.xlsx')
plt.rcParams['font.sans-serif']=['SimHei'] # 解决中文乱码
labels = np.array(['语文','数学','英语','物理','化学','生物']) # 标签
dataLenth = 6 # 数据长度
# 计算女生、男生各科平均成绩
df1 = df[df['性别']=='女'].mean().round(2)
df2 = df[df['性别']=='男'].mean().round(2)
print(df1-df2)
warning信息:
D:/06.Differential analysis.py:9: FutureWarning: Dropping of nuisance columns in DataFrame reductions (with 'numeric_only=None') is deprecated; in a future version this will raise TypeError. Select only valid columns before calling the reduction.
df1 = df[df['性别']=='女'].mean().round(2)
D:/06.Differential analysis.py:10: FutureWarning: Dropping of nuisance columns in DataFrame reductions (with 'numeric_only=None') is deprecated; in a future version this will raise TypeError. Select only valid columns before calling the reduction.
df2 = df[df['性别']=='男'].mean().round(2)