Python 如何仅使用具有唯一值的数据帧部分绘制时间序列

Python 如何仅使用具有唯一值的数据帧部分绘制时间序列,python,pandas,Python,Pandas,我有这个df: 指数 代码 日期 站 TMAX 特敏 聚丙烯 0 130 1/01/1991 楠 32.6 23.4 0 1. 130 2/01/1991 楠 31.2 22.4 0 ... ... ... ... ... ... ... 10865 130 31/12/2020 里加海滩 楠 楠 楠 10866 182 1/01/1991 楠 31.4 29.3 0,5 10867 182 2/01/1991 楠 33.5 30.1 0.6 ... ... ... ... ... ... ..

我有这个df:

指数 代码 日期 站 TMAX 特敏 聚丙烯 0 130 1/01/1991 楠 32.6 23.4 0 1. 130 2/01/1991 楠 31.2 22.4 0 ... ... ... ... ... ... ... 10865 130 31/12/2020 里加海滩 楠 楠 楠 10866 182 1/01/1991 楠 31.4 29.3 0,5 10867 182 2/01/1991 楠 33.5 30.1 0.6 ... ... ... ... ... ... ... 现在,您可以按车站代码访问每个车站,并绘制该车站的图形:

stations.get_group(182).plot('DATE',["TMAX", "TMIN", "PP"])
182号站的输出:

要在组上循环,请执行以下操作:

import matplotlib.pyplot as plt

for name, station_df in stations:
  #create plot
  plot = station_df.plot('DATE',["TMAX", "TMIN", "PP"])
  # save to file
  plt.savefig(str(name) + '.png')

如果您以代码或文件内容的形式提供数据帧,可以复制和粘贴,而不是图像,则会更容易为您提供帮助。我有371个站点,每个站点都有1991年1月1日至2020年12月31日的数据,因此以代码或文件的形式提供df有点困难。df的len为4057702。抱歉。是的,但您可以提供大约10行代码的代表性示例。好的,我会这样做,但当我想在站点中为i循环时:stations.get_group(i)。plot('DATE',[“TMAX”,“TMIN”,“PP”])我得到一个错误:“DataFrame”对象是可变的,因此它们无法散列。我如何循环得到所有图形的系列?我用一个例子更新了答案来解决这个问题。
import matplotlib.pyplot as plt

for name, station_df in stations:
  #create plot
  plot = station_df.plot('DATE',["TMAX", "TMIN", "PP"])
  # save to file
  plt.savefig(str(name) + '.png')