Skip to content

Instantly share code, notes, and snippets.

View pkaf's full-sized avatar
🔭

pkaf pkaf

🔭
  • Australia
View GitHub Profile
@pkaf
pkaf / user defined describe() for pandas
Created March 27, 2019 02:45
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
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@pkaf
pkaf / weighted_median.py
Created October 30, 2015 04:10
Weighted Median
import numpy as np
def weighted_median(x, weights):
#Sorting item and weights first
sort = np.argsort(x)
x = x[sort]
weights = weights[sort]
#Less than cumulative frequencies
@pkaf
pkaf / err_pdf.py
Created August 11, 2015 10:13
Returns a normal pdf at grid x that can be used as an error distribution. Here, grid x is linearly spaced between -cutoff to +cutoff sigma of the loc.
import scipy.stats as st
import numpy as np
def err_pdf( loc, scale, size=15, cutoff=5):
"""
PURPOSE
--------
Returns gaussian pdf at grid x that can be used as an error distribution.
Here, grid x is linearly spaced between -cutoff to +cutoff sigma of the loc.
@pkaf
pkaf / Scipy_quad_vectorization_example.ipynb
Created August 6, 2015 12:24
Vectorization of scipy.integrate.quad function
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@pkaf
pkaf / Sigma_NFW.ipynb
Created August 5, 2015 09:41
Formula for the surface density of NFW profile
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.