pandas取出包含某個值的所有行


pandas取出包含某個值的所有行
df = df[df[“from_account”].str.contains(“fcwhx”)]

pandas取出不包含某個值的所有行
df = df[~df[“from_account”].str.contains(“fcwhx”,“na=False”)]

df = df[df[“from_account”].str.contains(“fcwhx”)==False]

如果有空值,報錯:TypeError: bad operand type for unary ~: ‘float’
則用這個方法
df.other_group = df.other_group.fillna(’####@’)
df2 = df[~df[‘other_group’].str.contains(’####@’)]


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM