pandas - 当我从 pandas Dataframe 中选择系列时,reshape 是不推荐使用的问题
问题描述
当我尝试从数据框中获取一个系列时,我遇到了这个问题
anaconda3/lib/python3.6/site-packages/numpy/core/fromnumeric.py:52: FutureWarning: reshape 已弃用,将在后续版本中提出。请使用 .values.reshape(...) 代替 return getattr(obj, method)(*args, **kwds)
这是代码片段
for idx, categories in enumerate(categorical_columns):
ax = plt.subplot(3,3,idx+1)
ax.set_xlabel(categories[0])
box = [df[df[categories[0]] == atype].price for atype in categories[1]]
ax.boxplot(box)
解决方案
为了避免链式索引使用DataFrame.loc
:
box = [df.loc[df[categories[0]] == atype, 'price'] for atype in categories[1]]
并且对于删除是必要的FutureWarning
升级。pandas
matplotlib
推荐阅读
- python - 在字典上使用 map lambda 打印 3 个值
- bash - 如何在 tmux 中自动创建、命名和运行命令
- javascript - 如何使用javascript添加或删除li第一个孩子的类
- uml - 分析阶段使用的 UML 图
- r - 分布图中均值和百分位数的数据标签
- c# - 是否可以在 C# 中覆盖对象的返回?
- javascript - 请解释:在检查 runSaga 时未捕获,saga 参数必须是 Generator 函数
- java - 根据日期时间和持续时间列从表 t1 中选择学生待在一起的行
- python - 如何在匹配字符串的嵌套列表中找到索引的最小值和最大值?
- python - 安装tensorflow时如何修复虚拟环境中发生的EnvironmentError