Pandas groupby操作返回了object,但没有visu

2024-06-16 14:34:51 发布

您现在位置:Python中文网/ 问答频道 /正文

对熊猫来说非常陌生(2天),在我的奥斯卡奖数据集上运行以下groupby命令。在

df[(df.Award == 'Best Actress') & (df.Winner == 1.0)].groupby('Name')

我收到了以下输出,通常是在可视化之前,但这次不是。在

^{pr2}$

我期待着她们各自的女主角都能获得奥斯卡最佳女主角的称号。在

为什么不查特?在

编辑:

数据看起来像这样。在

    Year    Ceremony    Award   Winner  Name                Film
0   1928    1           Actor   0.0    Richard Barthelmess  The Noose
1   1928    1           Actor   1.0     Emil Jannings       The Last Command
2   1928    1           Actress 0.0     Louise Dresser      A Ship Comes In
3   1928    1         Actress   1.0     Janet Gaynor        7th Heaven
4   1928    1         Actress   0.0     Gloria Swanson      Sadie Thompson
5   1928    1         Art Dir   0.0     Rochus Gliese       Sunrise

Tags: the数据name命令df可视化集上best
2条回答

我认为您需要^{}并聚合一些函数,例如^{},如果需要过滤列Name的计数,以及绘图函数^{}或{a4}:

df[(df.Award == 'Best Actress') & (df.Winner == 1.0)].groupby('Name').size().plot() 

df[(df.Award == 'Best Actress') & (df.Winner == 1.0)].groupby('Name').size().plot.bar() 

或使用^{}

^{pr2}$

编辑:

我认为非常好的教程是10 Minutes to pandas。在

I received the following output, which usually precedes a visualisation, but not this time.

<pandas.core.groupby.DataFrameGroupBy object at 0x1166b8cc0>

这与可视化之前的结果不同。
这个pandasDataFrameGroupBy对象的文本表示。在

在Python中,一切都是一个对象。然而,并不是每一个物体都有一种直观的方式来呈现在屏幕上。有一个名为__repr__的方法控制该对象的文本表示。在本例中,df.groupby('col_name')返回一个DataFrameGroupBy对象。该对象的__repr__方法返回您看到的<pandas.core.groupby.DataFrameGroupBy object at 0x1166b8cc0>字符串。对于该方法来说,用<>包装生成对象的类的泛型描述是相当典型的。在

它看起来很眼熟。matplotlib为一个轴输出__repr__df.plot()产生{}。实际上,可以用分号df.plot();来抑制输出


尽管如此,我还是不确定你对图表的期望是什么

^{pr2}$

enter image description here

相关问题 更多 >