pythonpandas设置索引_python – pandas:使用(row,col)索引设置值
我不確定跟隨你,但是你使用DataFrame.ix選擇/設(shè)置單個元素:
In [79]: M
Out[79]:
one two three four
a -0.277981 1.500188 -0.876751 -0.389292
b -0.705835 0.108890 -1.502786 -0.302773
c 0.880042 -0.056620 -0.550164 -0.409458
d 0.704202 0.619031 0.274018 -1.755726
In [75]: M.ix[0]
Out[75]:
one -0.277981
two 1.500188
three -0.876751
four -0.389292
Name: a
In [78]: M.ix[0,0]
Out[78]: -0.27798082190723405
In [81]: M.ix[0,0] = 1.0
In [82]: M
Out[82]:
one two three four
a 1.000000 1.500188 -0.876751 -0.389292
b -0.705835 0.108890 -1.502786 -0.302773
c 0.880042 -0.056620 -0.550164 -0.409458
d 0.704202 0.619031 0.274018 -1.755726
In [84]: M.ix[(0,1),(0,1)] = 1
In [85]: M
Out[85]:
one two three four
a 1.000000 1.000000 -0.876751 -0.389292
b 1.000000 1.000000 -1.502786 -0.302773
c 0.880042 -0.056620 -0.550164 -0.409458
d 0.704202 0.619031 0.274018 -1.755726
您還可以按索引切片:
In [98]: M.ix["a":"c","one"] = 2.0
In [99]: M
Out[99]:
one two three four
a 2.000000 1.000000 -0.876751 -0.389292
b 2.000000 1.000000 -1.502786 -0.302773
c 2.000000 -0.056620 -0.550164 -0.409458
d 0.704202 0.619031 0.274018 -1.755726
總結(jié)
以上是生活随笔為你收集整理的pythonpandas设置索引_python – pandas:使用(row,col)索引设置值的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 辽宁舰再踏新征程
- 下一篇: 装修卧室的话,用欧兰泥的哪款产品更好呢?