【发布时间】:2016-01-14 00:40:09
【问题描述】:
我有一个包含犯罪时间序列数据的数据框,其中包含犯罪方面(如下所示)。我想在数据帧上执行分组图,以便可以探索一段时间内的犯罪趋势。
Offence Rolling year total number of offences Month
0 Criminal damage and arson 1001 2003-03-31
1 Drug offences 66 2003-03-31
2 All other theft offences 617 2003-03-31
3 Bicycle theft 92 2003-03-31
4 Domestic burglary 282 2003-03-31
我有一些代码可以完成这项工作,但它有点笨拙,并且失去了 Pandas 在单个绘图上提供的时间序列格式。 (我已经包含了一张图片来说明)。任何人都可以为我可以使用的此类情节提出一个成语吗?
我会求助于 Seaborn,但我不知道如何将 xlabel 格式化为时间序列。
[![subs = \[\]
for idx, (i, g) in enumerate(df.groupby("Offence")):
subs.append({"data": g.set_index("Month").resample("QS-APR", how="sum" ).ix\["2010":\],
"title":i})
ax = plt.figure(figsize=(25,15))
for i,g in enumerate(subs):
plt.subplot(5, 5, i)
plt.plot(g\['data'\])
plt.title(g\['title'\])
plt.xlabel("Time")
plt.ylabel("No. of crimes")
plt.tight_layout()][1]][1]
【问题讨论】:
-
您对 Pandas 中按年份
values.groupby(values.index.year)连续 6 年分组的石油与黄金价格 2x3 散点图的可重复示例感兴趣吗? -
当然。我只是想完成这个过程......
标签: python pandas matplotlib seaborn