我试图将分组数据降采样到每日平均值,计算每组,并绘制在一个图中得到的时间序列。 我的出发点是以下pd.DataFrame
:Groupd下采样和绘图pd.DataFrame
value time type
0.1234 2013-04-03 A
0.2345 2013-04-05 A
0.34564 2013-04-07 A
... ... ...
0.2345 2013-04-03 B
0.1234 2013-04-05 B
0.2345 2013-04-07 C
0.34564 2013-04-07 C
我想每天计算装置,每种类型的内容,并绘制时间序列这些日常手段的单一情节。
目前,我有这个...
names = list(test['type'].unique())
types = []
for name in names:
single = df.loc[df.type == name]
single = single.set_index(single.time, drop=False)
single = single.resample("D")
types.append(single)
for single, name in zip(types, names):
single.rename(columns={"value":name}, inplace=True)
combined = pd.concat(types, axis=1)
combined.plot()
...产生含有所需的输出组合数据帧和下面的情节:
在我看来,这可能是通过在初始数据帧上使用groupby
更容易实现,但到目前为止,我还无法使用此方法重现所需的绘图。
什么是“聪明的方式”来做到这一点?
编辑: 更大的数据样本(CSV,1000行)在:http://pastebin.com/gi16nZdh
感谢, 马蒂亚斯
您能否提供更大的示例数据集?在csv格式的pastebin中。 – Ffisegydd 2014-10-01 12:46:23
从数据框中添加1k行csv随机样本。 – Matthias 2014-10-01 13:06:44
它当然有帮助,谢谢。我必须将整个数据集的'pivot'转换为'pivot_table',但您肯定指出了正确的方向。 – Matthias 2014-10-01 13:38:52