我想将11列和9000行以上的pandas数据帧转换为一个序列,并绘制其自相关和部分自相关函数,并以序列作为输入。 10_before代表滞后= 10,8_before代表滞后= 8,利息是滞后= 0。每行代表1个数据。
我想问问是否可以将df转换为系列,或者是否有其他方法来获取acf和pacf?谢谢!
设法得到一个这样的系列,我如何使用这个来绘制acf和pacf?
0 [1.0, 1.0, 1.0, 2.0, 2.0, 1.0, 1.0, 1.0, 8.0, ...
1 [15.0, 1.0, 4.0, 2.0, 1.0, 5.0, 1.0, 1.0, 2.0,...
2 [2.0, 1.0, 100.0, 1.0, 5.0, 2.0, 10.0, 1.0, 1....
3 [3.0, 3.0, 7.0, 5.0, 2.0, 1.0, 1.0, 14.0, 1.0,...
4 [10.0, 1.0, 7.0, 2.0, 1.0, 2.0, 1.0, 4.0, 2.0,...
5 [1.0, 42.0, 4.0, 1.0, 2.0, 2.0, 1.0, 67.0, 2.0...
6 [1.0, 13.0, 2.0, 2.0, 2.0, 2.0, 1.0, 3.0, 1.0,...
7 [1.0, 5.0, 3.0, 2.0, 2.0, 15.0, 1.0, 3.0, 2.0,...
8 [3.0, 1.0, 13.0, 2.0, 15.0, 30.0, 14.0, 2.0, 1...
9 [1.0, 4.0, 2.0, 15.0, 30.0, 30.0, 4.0, 1.0, 1....
10 [42.0, 100.0, 30.0, 30.0, 30.0, 25.0, 67.0, 16...
dtype: object
我的代码如下:
a= np.array([trade_10before,trade_9before,trade_8before,trade_7before,trade_6before,trade_5before,trade_4before,trade_3before,trade_2before,trade_1before,trade])
a = a.tolist()
a = pd.Series(a)
plot_acf(a)
plot_pacf(a)
plt.show()
收到此错误:
During handling of the above exception, another exception occurred:
ValueError Traceback (most recent call last)
<ipython-input-29-a6cd38689337> in <module>()
70 })
71 df_acf1_past = df_acf1_past[new_order]
---> 72 df_acf1_past = pd.Series(df_acf1_past.iloc[:,:])
73 print(df_acf1_past)
74 plot_acf(df_acf1_past)
/usr/local/envs/py3env/lib/python3.5/site-packages/pandas/core/series.py in __init__(self, data, index, dtype, name, copy, fastpath)
262 else:
263 data = _sanitize_array(data, index, dtype, copy,
--> 264 raise_cast_failure=True)
265
266 data = SingleBlockManager(data, index, fastpath=True)
/usr/local/envs/py3env/lib/python3.5/site-packages/pandas/core/series.py in _sanitize_array(data, index, dtype, copy, raise_cast_failure)
3275 raise Exception('Data must be 1-dimensional')
3276 else:
-> 3277 subarr = _asarray_tuplesafe(data, dtype=dtype)
3278
3279 # This is to prevent mixed-type Series getting all casted to
/usr/local/envs/py3env/lib/python3.5/site-packages/pandas/core/common.py in _asarray_tuplesafe(values, dtype)
400 except ValueError:
401 # we have a list-of-list
--> 402 result[:] = [tuple(x) for x in values]
403
404 return result
ValueError: cannot copy sequence with size 11 to array axis with dimension 9683