Skip to content

Instantly share code, notes, and snippets.

View will-gao42's full-sized avatar

Will Gao will-gao42

  • Atlanta
View GitHub Profile
@will-gao42
will-gao42 / show_values_on_barplot.py
Created January 5, 2022 00:38
Display Values on Bars
def show_values_barplot(axs, space):
def _show_on_plot(ax):
for p in ax.patches:
_x = p.get_x() + p.get_width() + float(space)
_y = p.get_y() + p.get_height()
value = round(float(p.get_width()), 2)
ax.text(_x, _y, value, ha="left")
if isinstance(axs, np.ndarray):
for idx, ax in np.ndenumerate(axs):
@will-gao42
will-gao42 / eda.py
Last active December 14, 2021 17:37
EDA data processing snippets
def trim(df, col, qt):
"""
Trim certain percentiles on both sides of a dataframe
"""
p1 = df[col].quantile(qt)
p2 = df[col].quantile(1-qt)
trimmed_df = df[df[col].between(p1, p2)]
return trimmed_df