【发布时间】:2020-10-23 11:56:22
【问题描述】:
假设我有一个数据框 A,其属性名为“分数”。 我可以通过以下方式修改第二行的“分数”属性:
tmp = A.loc[2]
tmp.score = some_new_value
A.loc[2] = tmp
但我不能这样做:
A.loc[2].score = some_new_value
为什么?
【问题讨论】:
-
您收到错误消息还是什么?
-
听起来像是错字。对我来说它有效。我已经测试过这个
df = pd.DataFrame([[1, 2], [1, 3], [4, 6]], columns=['A', 'B']) \n df.loc[2].A = -1 -
@BERA 没有错误,但数据框未使用 some_new_value 更新
标签: python pandas numpy dataframe data-science