[問題] 請問dataframe怎麼用變數替換欄位

看板Python作者 (阿毛)時間2年前 (2021/09/20 11:37), 編輯推噓1(105)
留言6則, 4人參與, 2年前最新討論串1/1
舉例pd如下 0056 0050 2021/01/01 33 130 2021/01/02 34 131 想要用for依序抓取0056 & 0050 pd = pd["0056"] 這邊的0056怎麼用變數取代, 感謝 -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 111.243.28.144 (臺灣) ※ 文章網址: https://www.ptt.cc/bbs/Python/M.1632109078.A.DD6.html

09/20 11:58, 2年前 , 1F
df.columns?
09/20 11:58, 1F

09/20 12:03, 2年前 , 2F
可以考慮用dataframe.iloc,用index number去抓
09/20 12:03, 2F

09/20 16:35, 2年前 , 3F
盡量不要在pandas 使用 for loop
09/20 16:35, 3F

09/20 16:35, 2年前 , 4F
隨著row 和column數目增加 執行時間差很大
09/20 16:35, 4F

09/20 16:35, 2年前 , 5F

09/21 11:18, 2年前 , 6F
感謝各位大大
09/21 11:18, 6F
文章代碼(AID): #1XI08MtM (Python)