删除df中任意字段等于'null'字符串的行:

df=df.astype(str)#把df所有元素转为str类型
df=df[df['A'].isin(['null','NULL'])] #找出df的'A'列值为'null'或'NULL'(注意此处的null是字符串,不是空值)
df=df[~df['A'].isin(['null','NULL'])] #过滤掉A列为'null'或'NULL'的行,~表示取反

 

去掉任意一列为'null'值的行,目前只能想到用循环:

for col in list(df.columns):
df=df[~df[col].isin(['null','NULL'])]

 

去掉包含(而非等于)'null'字符串列的行:

df=df[~df['A'].str.contains('null')]

 

相关文章:

  • 2021-09-01
  • 2021-09-17
  • 2021-09-15
  • 2022-12-23
  • 2021-06-19
  • 2022-12-23
猜你喜欢
  • 2021-05-26
  • 2022-12-23
  • 2022-01-17
  • 2022-12-23
  • 2022-12-23
  • 2021-12-15
  • 2021-06-16
相关资源
相似解决方案