【发布时间】:2017-11-17 03:31:27
【问题描述】:
从 pandas 'g' 中的数据框中,我有以下数据:
index Speaker Date ARI Flesch Kincaid
0 Alan Greenspan 1996 15.234878 34.669383 14.533217
1 Alan Greenspan 1997 16.235605 31.415163 15.335869
11 Alan S. Blinder 2002 14.299481 41.847836 13.681203
12 Alan S. Blinder 2003 NaN NaN NaN
14 Alice M. Rivlin 1996 15.828971 33.394999 15.211662
使用下面的代码,我已经能够生成以下图表:
s = data
s['Date'] = pd.to_datetime(s['Date'], format='%Y-%m-%d %H:%M:%S')
s = s.set_index(['Date'])
grouped = s.groupby('Speaker').resample('AS').mean()
grouped = grouped.reset_index()
g = grouped.reset_index()
g["Date"] = g["Date"].dt.year
g.plot(x='Date', y='Flesch', colormap = cm.cubehelix, legend=True,
title="Auto", figsize=(12,10))
我希望图表为每条线包含不同的颜色,并放置一个图例,说明哪个“扬声器”与每条线相关联。任何帮助将不胜感激!
【问题讨论】:
-
我目前的想法是做一个数据透视表...
标签: python pandas matplotlib graph