【发布时间】:2021-07-09 06:45:06
【问题描述】:
我是 Python 新手,正在寻求帮助以随着时间的推移将 2 个数据帧相乘。任何帮助理解错误将不胜感激。
第一个数据帧(cov)
Date NoDur Durbl Manuf
2018-12-27 NoDur 0.000109 0.000112 0.000118
Durbl 0.000112 0.000339 0.000238
Manuf 0.000118 0.000238 0.000246
2018-12-28 NoDur 0.000109 0.000113 0.000117
Durbl 0.000113 0.000339 0.000239
Manuf 0.000117 0.000239 0.000242
2018-12-31 NoDur 0.000109 0.000113 0.000118
Durbl 0.000113 0.000339 0.000239
Manuf 0.000118 0.000239 0.000245
第二个数据帧(w)
Date NoDur Durbl Manuf
2018-12-27 -69.190732 -96.316224 -324.058486
2018-12-28 -113.831750 30.426696 -410.055587
2018-12-31 -101.365016 -16.613136 -362.232014
代码:
std = np.dot(np.transpose(w) , np.matmul(cov , w))
错误:
ValueError: matmul: Input operand 1 has a mismatch in its core dimension 0, with gufunc signature (n?,k),(k,m?)->(n?,m?) (size 12361 is different from 10)
我只展示了数据框中的小片段。原始 cov 数据帧为 123610 行 × 10 列,w 数据帧为 12361 行 × 10 列。
预期输出:
Date
2018-12-27 44.45574103083
2018-12-28 46.593367859
2018-12-31 45.282932300
提前非常感谢!!
【问题讨论】:
标签: python pandas dataframe numpy