绘制 Pandas DataSeries.GroupBy [英] Plotting a Pandas DataSeries.GroupBy
问题描述
我是 python 和 pandas 的新手,有以下 DataFrame
.
I am new to python and pandas, and have the following DataFrame
.
如何绘制 DataFrame
,其中每个 ModelID
是一个单独的图,saledate
是 x 轴,MeanToDate
是 y 轴吗?
How can I plot the DataFrame
where each ModelID
is a separate plot, saledate
is the x-axis and MeanToDate
is the y-axis?
尝试
data[40:76].groupby('ModelID').plot()
数据帧
推荐答案
您可以通过遍历 groupby
中的组来绘制图:
You can make the plots by looping over the groups from groupby
:
import matplotlib.pyplot as plt
for title, group in df.groupby('ModelID'):
group.plot(x='saleDate', y='MeanToDate', title=title)
有关使用 Pandas 数据框绘图的更多信息,请参见:
http://pandas.pydata.org/pandas-docs/stable/visualization.html
并循环遍历 groupby 对象:
http://pandas.pydata.org/pandas-docs/stable/groupby.html#iterating-through-groups
See for more information on plotting with pandas dataframes:
http://pandas.pydata.org/pandas-docs/stable/visualization.html
and for looping over a groupby-object:
http://pandas.pydata.org/pandas-docs/stable/groupby.html#iterating-through-groups
这篇关于绘制 Pandas DataSeries.GroupBy的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!