Python 熊猫人物传说的重构

Python 熊猫人物传说的重构,python,pandas,Python,Pandas,绘制图形后,我得到一个图形图例,如下所示: DataFrame1.plot(legend=False) patch,labels=ax.get_legend_handels_labels() DateFrame1.legend(loc='best') plt.show() 我如何删除(Temp,2005)中的“Temp”,让它变成“just 2005” DataFrame1有三个键:月、年、温度。使用独特的方法来获取不同年份的数据: DataFrame1.plot(legend=False)

绘制图形后,我得到一个图形图例,如下所示:

DataFrame1.plot(legend=False)
patch,labels=ax.get_legend_handels_labels()
DateFrame1.legend(loc='best')
plt.show()
我如何删除(Temp,2005)中的“Temp”,让它变成“just 2005”


DataFrame1有三个键:月、年、温度。

使用独特的方法来获取不同年份的数据:

DataFrame1.plot(legend=False)
patch,labels=ax.get_legend_handels_labels()
DateFrame1.legend(str(unique(DataFrame1['Year'].value)),loc='best')
plt.show()

所以它的工作是正确的。

你非常接近,你只需要用年份更新你的传奇:

ax = df.plot()

years = [2005, 2007, 2008, 2009, 2011, 2012]
# you can get years from you dataframe (but without seeing the dataframe I can't say exactly how)
# legend also accepts a Series or numpy array
ax.legend(years, loc='best')
plt.show()

这是一个好问题,但我想一定有办法做到这一点而不改变df…谢谢!你在这个项目上帮了我很多。还有我的英语D