第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會有你想問的

如何從具有特定值的 pandas DataFrame 數(shù)組列中選擇行

如何從具有特定值的 pandas DataFrame 數(shù)組列中選擇行

楊魅力 2022-11-09 17:00:12
我有帶有數(shù)組列的熊貓數(shù)據(jù)框:id,classes,text71,`["performer_146", "performer_42"]`,`adipiscing urna. molestie `72,["performer_42"],`a ligula odio elementum, neque suscipit. egestas Maecenas`73,["performer_146"],`vestibulum orci nec vestibulum, ligula orci et mauris lobortis, et Aliquam`74,["performer_0"],tincidunt non interdum nunc ultrices mi accumsan elementum arcu venenatis75,`["performer_146", "performer_42"]`, orci elementum non finibus dolor. Cras76,`["performer_42", "performer_146"]`,`mi lectus Maecenas eleifend neque amet, `77,["performer_146"],` platea placerat. odio Morbi rutrum, eu Cras`我閱讀了這個(gè) CSV 并將“類”列的值轉(zhuǎn)換為數(shù)組:import pandas as pdimport astdf = pd.read_csv(filename, quotechar='`')df['classes'] = df['classes'].apply(lambda x: ast.literal_eval(x))現(xiàn)在我想在“類”值中選擇帶有“performer_0”的行。像這樣:df['performer_0' in df['classes']]但是這段代碼不起作用:Traceback(最近一次調(diào)用最后一次):文件“d:\pyenv\pandas\lib\site-packages\pandas\core\indexes\base.py”,第 2657 行,在 get_loc return self._engine.get_loc(key) File 中pandas_libs\index.pyx",第 108 行,在 pandas._libs.index.IndexEngine.get_loc 文件 "pandas_libs\index.pyx",第 132 行,在 pandas._libs.index.IndexEngine.get_loc 文件 "pandas_libs\hashtable_class_helper.pxi" ,第 1601 行,在 pandas._libs.hashtable.PyObjectHashTable.get_item 文件“pandas_libs\hashtable_class_helper.pxi”,第 1608 行,在 pandas._libs.hashtable.PyObjectHashTable.get_item KeyError: False我怎樣才能做到這一點(diǎn)?
查看完整描述

2 回答

?
滄海一幻覺

TA貢獻(xiàn)1824條經(jīng)驗(yàn) 獲得超5個(gè)贊

我發(fā)現(xiàn)最簡單的方法是組合apply和選擇:

df[df['classes'].apply(lambda x: 'performer_0' in x)]


查看完整回答
反對 回復(fù) 2022-11-09
?
藍(lán)山帝景

TA貢獻(xiàn)1843條經(jīng)驗(yàn) 獲得超7個(gè)贊

如果你在 pandas 0.25+ 上工作,你可以使用explode

df[df['classes'].explode().eq(performer_0).any(level=0)]


查看完整回答
反對 回復(fù) 2022-11-09
  • 2 回答
  • 0 關(guān)注
  • 157 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號