Skip to content

Instantly share code, notes, and snippets.

@mrahul17
Last active January 24, 2016 07:57
Show Gist options
  • Save mrahul17/ff33bbbd7970988372d0 to your computer and use it in GitHub Desktop.
Save mrahul17/ff33bbbd7970988372d0 to your computer and use it in GitHub Desktop.
Pandas utility scripts
#check if na values exist at all
df.isnull().any().any()
#if above returns true for any series
df.isnull().any()
#check for NA values
data.isnull().sum()
#replace NA values
# for real values
data['series_to_replace'] = data['series_to_replace'].fillna(data.mean()['series_to_replace'])
# convert string to int
mapping = {string:int}
data.replace({'column_name':mapping})
#find number of unique items in a series
data['series_name'].nunique()
#find uniquevalues
pd.unique(data['column_name'])
#this http://stackoverflow.com/questions/17995328/changing-values-in-pandas-dataframe-doenst-work
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment