Skip to content

Instantly share code, notes, and snippets.

@pkaf
Created March 27, 2019 02:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pkaf/0357606d928384fbf7257136d46a8820 to your computer and use it in GitHub Desktop.
Save pkaf/0357606d928384fbf7257136d46a8820 to your computer and use it in GitHub Desktop.
This implements user defined list of functions to summarise aka describe() any pandas dataframe
import pandas as pd
import numpy as np
def describe(x):
data = [np.mean(x), x.std(), x.median() - x.quantile(0.25),
x.median(), x.quantile(0.75) - x.median(), np.sum(x)]
names = ['mean', 'std', '-err', '50%', '+err', 'sum']
return pd.DataFrame(data, index=names).T
#functional call
#instead of calling default pandas command using df.describe()
#one has to call the following
df.apply(describe)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment