Ambitions_G 2021-08-10 17:01 采纳率: 100%
浏览 4376
已结题

Python使用pd.mean()函数后出现Warning,请问该如何解决?

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)  

  • 写回答

1条回答 默认 最新

  • python收藏家 2021-08-10 17:50
    关注

    看你取到的df数据是不是含有其他非数值的列,或者你索引的时候就只取各科目列就行,warning只要不报错也没关系

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

问题事件

  • 系统已结题 8月19日
  • 已采纳回答 8月11日
  • 创建了问题 8月10日

悬赏问题

  • ¥15 镍氢电池充电器设计实物使用原理
  • ¥15 逻辑谓词和消解原理的运用
  • ¥15 三菱伺服电机按启动按钮有使能但不动作
  • ¥15 js,页面2返回页面1时定位进入的设备
  • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号