简体   繁体   English

Pandas Dataframe Bar Plot - 定性变量?

[英]Pandas Dataframe Bar Plot - Qualitative Variable?

I am looking to create a simple bar plot, where the grouped qualitative values for "source" are the x-axis and the quantiative values of "retweet_count" are the y-axis. 我希望创建一个简单的条形图,其中“source”的分组定性值是x轴,“retweet_count”的量化值是y轴。

I want the total number of retweets by source. 我想要按来源转发的总数。

    _id                         created_at              geo     id      retweet_count   source  text
0   52c2388a0b434a166c94a648    2013-12-31 03:22:30     None    417858271957893121  0   web     @sirenasmaster I'm one of 4 people that I foll...
1   52c2388a0b434a166c94a649    2013-12-31 03:22:29     None    417858271350120449  0   Twitter for iPhone  Thanks Mack brown always looked up to you and ...
2   52c2388a0b434a166c94a64a    2013-12-31 03:22:26     None    417858255121948672  0   Twitter for iPhone  @CottonGent I never said case was awesome, but...
3   52c2388a0b434a166c94a64b    2013-12-31 03:22:20     None    417858229625163776  0   buzztap     Longhorn Digest (Scout) >> UA Game: DB C...
4   52c2388a0b434a166c94a64c    2013-12-31 03:22:15     None    417858211186626560  1   web     RT @rudyp_: Marvin is on it tonight. He's a tr...
5   52c2388a0b434a166c94a64d    2013-12-31 03:22:12     None    417858197550931970  2   Twitter for iPhone  RT @marvintran76: If you're a Longhorn and you...
6   52c2388a0b434a166c94a64e    2013-12-31 03:21:49     None    417858102042443776  1   Twitter for iPhone  Always will be a Longhorn Fan 👌🐂
7   52c2388a0b434a166c94a64f    2013-12-31 03:21:38     None    417858055955423232  0   Twitter for Android     Longhorn and duke basketball, and lakers are o...
8   52c2388a0b434a166c94a650    2013-12-31 03:21:34     None    417858036716142592  1   Twitter for iPhone  Marvin is on it tonight. He's a true longhorn ...
9   52c2388a0b434a166c94a651    2013-12-31 03:21:32     None    417858031880134657  0   web     @ChipBrownOB but twice as many as there are Lo..

If I use the following simple code, it gives me a bar for each individual source entry: 如果我使用以下简单代码,它会为每个单独的源条目提供一个条形码:

df.plot(x='source', y='retweet_count', kind='bar')

This is something I've been banging my head on but it probably right in front of me. 这是我一直在喋喋不休的事情,但它可能就在我面前。

You can groupby and plot then: 你可以分组并绘制:

>>> df.groupby('source')['retweet_count'].sum().plot(kind='bar')
<matplotlib.axes.AxesSubplot object at 0x039C8070>

结果

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM