AttributeError:"numpy.int64"对象在Anaconda的Python 3.5中没有属性"timestamp" [英] AttributeError: 'numpy.int64' object has no attribute 'timestamp' in python 3.5 in Anaconda

查看:184
本文介绍了AttributeError:"numpy.int64"对象在Anaconda的Python 3.5中没有属性"timestamp"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是学习机器学习的新手,因此请关注YouTube上的精彩教程.但是下面的代码给我一个错误.我在这里读过类似的问题,但是timetuple()不能解决我的问题,也无法解决视频中的任何问题.

I am a newbie in learning Machine Learning, so following a great tutorial in YouTube. But the following code is giving me an error. I read a similar question in here, but timetuple() does not solve my case, nor any solutions from the video.

这是我的代码:

import pandas as pd
import quandl, math
from datetime import datetime, date, time, timedelta
import time
import numpy as np

from sklearn import preprocessing, cross_validation, svm
from sklearn.linear_model import LinearRegression

import matplotlib.pyplot as plt  #plot stuff, how to plot in graph
from matplotlib import style     #nice looking thing 
style.use('ggplot')              #which nice-looking-thing i wanna use

quandl.ApiConfig.api_key = '...' #erased my key for secrecy
df = quandl.get_table('WIKI/PRICES')


## ... ##other irrelevant code snippets

forecast_out = int(math.ceil(0.01*len(df)))
df['label'] = df[forecast_col].shift(-forecast_out)

X = np.array(df.drop(['label'],1)) 
X = preprocessing.scale(X)
X_lately = X[-forecast_out:]    
X = X[:-forecast_out]

df.dropna(inplace=True)
y = np.array(df['label'])
y = np.array(df['label'])

# ... #other irrelevant code snippets

forecast_set = clf.predict(X_lately)
df['Forecast'] = np.nan

last_date = df.iloc[-1].name
last_unix = last_date.timestamp() ###MAIN attribute error found here
one_day = 86400
next_unix = last_unix + one_day

对于上面的代码,出现以下错误:

For this above code, I got this following error :

AttributeError                            Traceback (most recent call last)
<ipython-input-8-4a1a193ea81d> in <module>()
      1 last_date = df.iloc[-1].name
----> 2 last_unix = last_date.timestamp()
      3 one_day = 86400
      4 next_unix = last_unix + one_day

AttributeError: 'numpy.int64' object has no attribute 'timestamp'

尽管互联网上有很多解决方案,但我找不到解决方案.我在蟒蛇中使用Python 3.5. timetuple()对我不起作用,并且发生相同的属性错误.

I couldn't figure out the solution though there are many solutions in the internet but nothing worked for me. I am using Python 3.5 in anaconda. timetuple() doesn't work for me and same attribute error occurs.

推荐答案

您好,有时会更改此类操作索引. Date列不再是索引.

Hi sometimes when do such operations index is changed. Date column is no more index.

 df=df.set_index('Date')

只需在创建dataframe之后添加即可.
示例-
df = quandl.get_table('WIKI/PRICES')df=pd.read_csv("stock_data.csv")在此之后添加.

Just add this just after you create a dataframe.
Example-
df = quandl.get_table('WIKI/PRICES') OR df=pd.read_csv("stock_data.csv") add after this.

这篇关于AttributeError:"numpy.int64"对象在Anaconda的Python 3.5中没有属性"timestamp"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆