我有一个包含收盘价的数据框:
Date World EN UT IND MAT CS CD IT FN TC HC
0 1997-06-13 939.3672 96.0238 75.2840 105.2635 124.7077 80.4562 82.8793 59.5524 88.0499 60.2713 69.0940
1 1997-06-20 944.3056 95.3351 75.8622 106.0365 124.8201 80.0543 82.5784 60.3146 89.0581 60.5441 70.1105
2 1997-06-27 945.2955 95.2789 76.2589 105.5658 124.0537 79.9143 82.2506 60.4379 89.4949 60.4505 71.1205
3 1997-07-04 966.1033 99.9787 78.0173 107.2277 125.4118 81.8571 83.0711 62.0707 91.3587 61.7000 73.4790
4 1997-07-11 966.9804 98.1188 77.1991 107.5794 125.7659 81.9250 83.4724 64.3737 91.0970 60.8316 72.9100
df_koersen.info()
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 1197 entries, 0 to 1196
Data columns (total 12 columns):
# Column Non-Null Count Dtype
--- ------ -------------- -----
0 Date 1197 non-null datetime64[ns]
1 World 1197 non-null float64
2 EN 1197 non-null float64
3 UT 1197 non-null float64
4 IND 1197 non-null float64
5 MAT 1197 non-null float64
6 CS 1197 non-null float64
7 CD 1197 non-null float64
8 IT 1197 non-null float64
9 FN 1197 non-null float64
10 TC 1197 non-null float64
11 HC 1197 non-null float64
dtypes: datetime64[ns](1), float64(11)
memory usage: 112.3 KB
我正在尝试使用以下函数创建一个 varcov 矩阵:
varcov = df_koersen.pct_change().apply(lambda x: np.log(x+1)).cov
但我不断收到此错误:
TypeError: cannot perform __truediv__ with this index type: DatetimeArray
我需要进行哪些调整才能使该功能正常工作?
谢谢!
Try
df_koersen.set_index('Date')
varcov = df_koersen.pct_change().apply(lambda x: np.log(x+1)).cov
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)