Python:“Pandas 数据转换为对象的 numpy dtype。使用 np.asarray(data) 检查输入数据。”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/46534512/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Python: "Pandas data cast to numpy dtype of object. Check input data with np.asarray(data)."
提问by Julian Almanzar
I'm trying to create an ARIMA model for forecasting a time-serie with some data from my server, and i keep the error on the title showing up and i don't know what type of object i need. Here's the code:
我正在尝试创建一个 ARIMA 模型,用于使用来自我的服务器的一些数据预测时间序列,并且我一直显示标题上的错误,但我不知道我需要什么类型的对象。这是代码:
frame = pd.read_sql(query, con=connection)
connection.close()
frame['time_field'] = pd.to_timedelta(frame['time_field'])
print(frame.head(10))
#fitting
model = ARIMA(frame, order=(5,1,0))
model_fit = model.fit(disp=0)
i've seen examples like this one: https://machinelearningmastery.com/arima-for-time-series-forecasting-with-python/
我见过这样的例子:https: //machinelearningmastery.com/arima-for-time-series-forecasting-with-python/
where they use dates instead of times with the respectives values. This is the output of the frame value:
他们使用日期而不是具有各自值的时间。这是帧值的输出:
time_field value_field
0 00:00:14 283.80
1 00:01:14 271.97
2 00:02:14 320.53
3 00:03:14 346.78
4 00:04:14 280.72
5 00:05:14 277.41
6 00:06:14 308.65
7 00:07:14 321.27
8 00:08:14 320.68
9 00:09:14 332.32
回答by Rafael P. Miranda
I had a similar problem and worked for me using pandas Series
instead of the DataFrame
, with the timestamp column as index
我遇到了类似的问题,并使用 pandasSeries
而不是DataFrame
,以时间戳列作为索引对我来说有效
data = pd.Series(frame.value_fields, index=frame.time_field)
model = ARIMA(data, order=(5,1,0))
model_fit = model.fit(disp=0)