【发布时间】:2017-10-13 08:00:09
【问题描述】:
当我尝试向我的绘图添加注释时出现此错误 - ValueError: invalid literal for float(): 10_May。
我的数据框:
我的代码(我在绘图之前使用to_datetime 和strftime,因为我需要对存储为字符串的日期进行排序):
# dealing with dates as strings
grouped.index = pd.to_datetime(grouped.index, format='%d_%b')
grouped = grouped.sort_index()
grouped.index = grouped.index.strftime('%d_%b')
plt.annotate('Peak',
(grouped.index[9], grouped['L'][9]),
xytext=(15, 15),
textcoords='offset points',
arrowprops=dict(arrowstyle='-|>'))
grouped.plot()
grouped.index[9] 返回u'10_May',而grouped['L'][9] 返回10.0。
我知道熊猫希望索引是浮动的,但我认为我可以通过 df.index[] 访问它。感谢您的建议。
【问题讨论】:
标签: python-2.7 pandas matplotlib dataframe jupyter