[問題] INDEX尋找文字

看板Python作者 (洨大魯蛇ㄍ)時間5年前 (2019/12/12 14:44), 編輯推噓0(006)
留言6則, 2人參與, 5年前最新討論串1/1
pandas 的 DataFrame df 抓取columns df.columns Index(['DAY', 'MONTH', 'YEAR',...], dtype='object') 欄位很多情況下 但我今天不知道所有欄位名稱 想知道某個欄位名稱有"A" 用甚麼指令比較快 是要找欄位名稱 不是要欄位裡的資料 -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 61.230.67.115 ※ 文章網址: https://www.ptt.cc/bbs/Python/M.1576133066.A.459.html

12/12 17:56, 5年前 , 1F
df.columns.values 或
12/12 17:56, 1F

12/12 17:56, 5年前 , 2F
df.columns.values.to_numpy()
12/12 17:56, 2F

12/12 17:56, 5年前 , 3F
會輸出numpy
12/12 17:56, 3F

12/12 18:00, 5年前 , 4F
阿你是要contains吧 當我沒說
12/12 18:00, 4F

12/12 18:02, 5年前 , 5F
df.filter(regex=“A”, axis=1)
12/12 18:02, 5F

12/12 18:03, 5年前 , 6F
要濾出來的 column name 就在最後加 .columns
12/12 18:03, 6F
文章代碼(AID): #1TyU7AHP (Python)
文章代碼(AID): #1TyU7AHP (Python)