1
当我尝试向我的图中添加注释时出现此错误 - ValueError: invalid literal for float(): 10_May
。ValueError:无效文字为float():在熊猫中添加注释时
我的数据框:
我的代码(我用to_datetime
和strftime
ploting之前,我需要整理这些被存储为字符串日期):
# 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 []访问它。将感谢您的建议。
Supeer,周末愉快! – jezrael