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