如何访问 pandas 数据框的子列并将它们绘制在 Python 中
How to access subcolumns of pandas dataframe and plot them in Python
我有以下 pandas 数据框。我如何访问此数据框的子列并绘制它们(例如,使用箱线图绘制最小值的分布)
我正在使用以下 python 语句,但我没有得到输出。
df.boxplot(列=['score']['min'])
因为它是 multi-level 列,所以您必须将其作为元组传递。要阅读更多索引 multi-level 结构,请阅读 pandas 文档 MultiIndex / advanced indexing
.
df.boxplot(column=[('score', 'min')])
或者,使用df.xs
, in this case return type is Series
, to boxplot Series
use Series.plot.box
。
df.xs(('score', 'min')).plot.box()
我有以下 pandas 数据框。我如何访问此数据框的子列并绘制它们(例如,使用箱线图绘制最小值的分布)
我正在使用以下 python 语句,但我没有得到输出。
df.boxplot(列=['score']['min'])
因为它是 multi-level 列,所以您必须将其作为元组传递。要阅读更多索引 multi-level 结构,请阅读 pandas 文档 MultiIndex / advanced indexing
.
df.boxplot(column=[('score', 'min')])
或者,使用df.xs
, in this case return type is Series
, to boxplot Series
use Series.plot.box
。
df.xs(('score', 'min')).plot.box()