Advertisement
Guest User

Untitled

a guest
Jun 16th, 2019
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.46 KB | None | 0 0
  1. # Replace all empty lists ([], '[]') in dataframe with NaN's
  2. df = df.mask(df.applymap(str).eq('[]'))
  3.  
  4. # Replace all zeros in dataframe with NaN's
  5. df[df == 0.0] = np.nan
  6.  
  7. # Replace empty strings in dataframe with NaN's
  8. df.replace('', np.nan, inplace=True)
  9.  
  10. # Replace all strings with value 'null' in a dataframe with NaN
  11. df.replace('null', np.NaN, inplace=True)
  12.  
  13. mask = df.applymap(str).isin(["[]", 0.0, "", "null"])
  14. df = df.where(~mask, other=np.nan)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement