首页 > 解决方案 > 当我从 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)

标签: pandasnumpydataframe

解决方案


为了避免链式索引使用DataFrame.loc

box = [df.loc[df[categories[0]] == atype, 'price'] for atype in categories[1]]

并且对于删除是必要的FutureWarning升级。pandasmatplotlib


推荐阅读