绘制按ID分组的时间序列 [英] Plot a time series grouped by id
本文介绍了绘制按ID分组的时间序列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想绘制一个按ID分组的时间序列.所以那个时间是我的 x 值,值"是我的 y 值.如何绘制按 'id' 1 分组的 x 和 y?
id时间值1 1 0.31 2 0.61 3 0.92 1 0.12 2 0.32 3 0.63 1 0.23 2 0.43 3 0.5
解决方案
我认为您可以使用
df = df.pivot(index='time', columns='id', values='value')打印 (df)ID 1 2 3时间1 0.3 0.1 0.22 0.6 0.3 0.43 0.9 0.6 0.5df.plot()plt.show()
I want to plot a time series grouped by id. So that time is my x-value and 'value' is my y-value. How can I plot x and y grouped by 'id' 1?
id time value
1 1 0.3
1 2 0.6
1 3 0.9
2 1 0.1
2 2 0.3
2 3 0.6
3 1 0.2
3 2 0.4
3 3 0.5
解决方案
I think you can use pivot
with DataFrame.plot.bar
or only DataFrame.plot
:
import matplotlib.pyplot as plt
df = df.pivot(index='time', columns='id', values='value')
print (df)
id 1 2 3
time
1 0.3 0.1 0.2
2 0.6 0.3 0.4
3 0.9 0.6 0.5
df.plot.bar()
plt.show()
df = df.pivot(index='time', columns='id', values='value')
print (df)
id 1 2 3
time
1 0.3 0.1 0.2
2 0.6 0.3 0.4
3 0.9 0.6 0.5
df.plot()
plt.show()
这篇关于绘制按ID分组的时间序列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文