Skip to content

Instantly share code, notes, and snippets.

@pra-dan
Created August 19, 2020 08:34
Show Gist options
  • Save pra-dan/32afae4daffb3c4a323b54c6a0420664 to your computer and use it in GitHub Desktop.
Save pra-dan/32afae4daffb3c4a323b54c6a0420664 to your computer and use it in GitHub Desktop.
pandas cheatsheet :)
  1. Remove all entries with empty strings OR empty cells
for col in rawData.columns: # Iterate over all cols
  #print(f'col: {col}')  
  
  # Replace empty strings (if any), with NaN
  df[col].replace('', np.nan, inplace=True)
  
  # Remove all rows with any entry = NaN
  df.dropna(subset=[col], inplace=True)
  1. List number of elements in each column
print(rawData.count(axis=0))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment