I';我试着运行Ipython笔记本电脑,除了它';他给了我一个“答案”;aType timedelta64“;错误
我对大数据很感兴趣,最近我偶然发现了这个Ipython笔记本: 并立即下载并尝试运行它。前十几个单元格运行正常,甚至matplotlib图表也正常 直到我讲到这些台词:I';我试着运行Ipython笔记本电脑,除了它';他给了我一个“答案”;aType timedelta64“;错误,python,numpy,pandas,ipython,gis,Python,Numpy,Pandas,Ipython,Gis,我对大数据很感兴趣,最近我偶然发现了这个Ipython笔记本: 并立即下载并尝试运行它。前十几个单元格运行正常,甚至matplotlib图表也正常 直到我讲到这些台词: # Lets use real dates for plotting days_from_start=pd.Series(t_all.index*30).astype('timedelta64[D]') dates_for_plot=date.min()+days_from_start time_labels=dates_fo
# Lets use real dates for plotting
days_from_start=pd.Series(t_all.index*30).astype('timedelta64[D]')
dates_for_plot=date.min()+days_from_start
time_labels=dates_for_plot.map(lambda x: str(x.year)+'-'+str(x.month))
给出了一条很长的错误消息:
--------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-27-4a793ff06024> in <module>()
1 # Lets use real dates for plotting
----> 2 days_from_start=pd.Series(t_all.index*30).astype('timedelta64[D]')
3 dates_for_plot=date.min()+days_from_start
4 time_labels=dates_for_plot.map(lambda x: str(x.year)+'-'+str(x.month))
如果你需要我发布整个信息,我会的,但我认为核心问题可能与numpy和pandas版本之间的冲突有关
有经验的人能告诉我该怎么改变吗?我正在运行Ubntu 14.04。问题是,Numpy不再支持从浮点创建
timedelta64
对象(可能是在笔记本发布时)
在转换为timedelta64
之前,需要先将按比例放大的索引转换为整数
days_from_start=pd.Series(t_all.index*30).astype('int').astype('timedelta64[D]')
明白了,现在试试这个。是的,解决了那个问题。谢谢,非常感谢。
days_from_start=pd.Series(t_all.index*30).astype('int').astype('timedelta64[D]')