[英]Iteratively plot data through datetime in pandas dataframe
I have a dataframe here that contains a value daily since 2000 (ignore the index).我在这里有一个 dataframe ,其中包含自 2000 年以来每天的值(忽略索引)。
Extent Date
6453 13.479 2001-01-01
6454 13.385 2001-01-02
6455 13.418 2001-01-03
6456 13.510 2001-01-04
6457 13.566 2001-01-05
I would like to make a plot where the x-axis is the day of the year, and the y-axis is the value.我想做一个 plot ,其中 x 轴是一年中的一天,y 轴是值。 The plot would contain 20 different lines, with each line corresponding to the year of the data.
plot 将包含 20 条不同的行,每行对应于数据的年份。 Is there an intuitive way to do this using pandas, or is it easier to do with matplotlib?
有没有一种直观的方法可以使用 pandas 来做到这一点,还是使用 matplotlib 更容易做到这一点?
Here is a quick paint sketch to illustrate.这是一个快速的绘画草图来说明。
One quick way is to plot x-axis
as strings:一种快速方法是将 plot
x-axis
作为字符串:
df['Date'] = pd.to_datetime(df['Date'])
(df.set_index([df.Date.dt.strftime('%m-%d'),
df.Date.dt.year])
.Extent.unstack()
.plot()
)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.