日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) >

pythonpandas设置索引_python – pandas:使用(row,col)索引设置值

發(fā)布時(shí)間:2025/4/5 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 pythonpandas设置索引_python – pandas:使用(row,col)索引设置值 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

我不確定跟隨你,但是你使用DataFrame.ix選擇/設(shè)置單個(gè)元素:

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)索引设置值的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。