2015-08-26 42 views
0

我在推特字发病率的数据帧,与第一鸣叫的日期作为索引中列出:熊猫轨道字发病率日期

    Kill Counts Killing Counts Murder Count Violence Count 
     2015-07-01 0 0 0 0 
     2015-07-01 0 0 0 0 
     2015-07-02 0 0 0 0 
     2015-07-02 0 0 0 0 
     2015-07-06 0 0 0 0 

我想压缩所有重复的日子变成一条线,然后每天绘制这些词的发生率。

df4 =df3.groupby([df3.index]) 

返回

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

但输出似乎是每天无用图,其没有少具有若干X轴每天蜱。我是matlab新手,我如何按日期分组?

我每天的tweets数量的图表一起工作:

df.groupby([df.index]).count().plot(kind='bar') 

df4 =df3.groupby([df3.index.date]) 

回报

AttributeError: 'Index' object has no attribute 'date' 

回答

1

如果我理解你的要求,我认为这将工作:

df.groupby(df.index).sum() 

这会使

In [3]: df.groupby(df.index).sum() 
Out[3]: 
      Kill Counts Killing Counts Murder Count  Violence Count 
2015-07-01   0    0    0     0 
2015-07-02   0    0    0     0 
2015-07-06   0    0    0     0 

count()只是计数的出现对于每个GROUPBY行的数量并没有真正重视什么在每个单元中,而sum()将总结每个电池中值为每个GROUPBY行。

没有冒犯,但是你的例子有点无聊,因为所有东西都绘制为零,但这是我绘制该groupby对象时得到的结果(在上面的代码行结尾处用matplotlib绘制的.plot() - 我想象的调用在matlab中是类似的):

enter image description here