我在pandas中设置了一个简单的DataFrame:
a = pandas.DataFrame([[1,2,3], [4,5,6], [7,8,9]], columns=['a','b','c'])
>>> print a
a b c
0 1 2 3
1 4 5 6
2 7 8 9
Run Code Online (Sandbox Code Playgroud)
我希望能够改变最后一行中的单个元素.在pandas == 0.13.1我可以使用以下内容:
a.iloc[-1]['a'] = 77
>>> print a
a b c
0 1 2 3
1 4 5 6
2 77 8 9
Run Code Online (Sandbox Code Playgroud)
但在更新到pandas == 0.14.1后,我在执行此操作时收到以下警告:
SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_index,col_indexer] = value instead
Run Code Online (Sandbox Code Playgroud)
问题当然是-1不是索引a,所以我不能使用loc.正如警告所示,我没有更改 …