DataFrame筛选后返回的是一个新拷贝?不能返回引用吗?

acneyang 2018-01-10 04:49:59
求教,我希望修改df4(筛选后得到的DataFrame),修改结果反映到原df1上,没有简单办法吗?
df1=pd.DataFrame(np.arange(16).reshape((4,4)),index=['a','b','c','d'],columns=['one','two','three','four'])
print df1
df2 = df1.copy()
df3 = df1
df4 = df1[df1['three'] > 2] #经过过滤df4已经是一个新的DataFrame对象,对它的修改不会反映到df1上
df2['one'][1] = 222
df3['one'][1] = 333
df4['one'][1] = 444
print df1
print df2
print df3
print df4
...全文
729 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
acneyang 2018-01-11
  • 打赏
  • 举报
回复
acneyang 2018-01-10
  • 打赏
  • 举报
回复
运行结果 one two three four a 0 1 2 3 b 4 5 6 7 c 8 9 10 11 d 12 13 14 15 one two three four a 0 1 2 3 b 333 5 6 7 c 8 9 10 11 d 12 13 14 15 one two three four a 0 1 2 3 b 222 5 6 7 c 8 9 10 11 d 12 13 14 15 one two three four a 0 1 2 3 b 333 5 6 7 c 8 9 10 11 d 12 13 14 15 one two three four b 4 5 6 7 c 444 9 10 11 d 12 13 14 15

37,720

社区成员

发帖
与我相关
我的任务
社区描述
JavaScript,VBScript,AngleScript,ActionScript,Shell,Perl,Ruby,Lua,Tcl,Scala,MaxScript 等脚本语言交流。
社区管理员
  • 脚本语言(Perl/Python)社区
  • IT.BOB
加入社区
  • 近7日
  • 近30日
  • 至今

试试用AI创作助手写篇文章吧