【发布时间】:2020-02-29 09:12:01
【问题描述】:
原帖的编辑版本
我有一个完全用 NaN 填充的数据框。具体来说:
print(histPrice['Allocation %'])
[Output]:
Symbols SPY GLD TLT MA QQQ TIP
Date
2019-11-01 NaN NaN NaN NaN NaN NaN
2019-10-31 NaN NaN NaN NaN NaN NaN
2019-10-30 NaN NaN NaN NaN NaN NaN
2019-10-29 NaN NaN NaN NaN NaN NaN
2019-10-28 NaN NaN NaN NaN NaN NaN
2019-10-25 NaN NaN NaN NaN NaN NaN
2019-10-24 NaN NaN NaN NaN NaN NaN
2019-10-23 NaN NaN NaN NaN NaN NaN
2019-10-22 NaN NaN NaN NaN NaN NaN
2019-10-21 NaN NaN NaN NaN NaN NaN
2019-10-18 NaN NaN NaN NaN NaN NaN
我有以下numpy 数组:
x = np.array([0.1,0.3,0.2,0.1,0.1,0.2])
我尝试通过以下方式将数组分配给 2019-10-30 行:
histPrice['Allocation %'].iloc[2] = x
还有
histPrice['Allocation %'].iloc[2,:] = x
然而,两者都导致:
print(histPrice['Allocation %'].iloc[2])
[Output]:
Symbols
SPY NaN
GLD NaN
TLT NaN
MA NaN
QQQ NaN
TIP NaN
Name: 2019-10-30 00:00:00, dtype: float64
我很困惑为什么它仍在输出NaN。任何帮助将不胜感激。
【问题讨论】:
-
你想用 np 数组替换表格的第三行吗?
-
@Tserenjamts 我只是想用数组替换特定行
-
histPrice 是什么类型的?
-
@aprilangel histPrice is 'pandas.core.frame.DataFrame'
-
@Drive2blue 但看起来 histPrice['Allocation %'] 也是一个数据框
标签: python pandas dataframe numpy