Skip to content

Instantly share code, notes, and snippets.

@ericgitonga
Last active June 24, 2021 06:34
Show Gist options
  • Save ericgitonga/705e913c3959e4d0b9745ffab5413d6e to your computer and use it in GitHub Desktop.
Save ericgitonga/705e913c3959e4d0b9745ffab5413d6e to your computer and use it in GitHub Desktop.
df["month_number"] = df.index.month
df["day"] = df.index.day
high_day_list = []
for year in list(df["year"].unique()):
df_year = df.groupby(["year","month","month_number","day"])["funded_amount"].sum().reset_index()
df_year = df_year[df_year["year"] == year][["year","month","day","funded_amount", "month_number"]]
for month in list(df["month"].unique()):
df_high_day = df_year[df_year["month"] == month]
df_high_day = df_high_day[df_high_day["funded_amount"] == df_high_day["funded_amount"].max()]
high_day_list.append(df_high_day)
df_high_day = pd.concat(high_day_list).reset_index(drop=True)
sorted_df_high_day = []
for year in list (df_high_day["year"].unique()):
sorted_df_high_day.append(df_high_day[df_high_day["year"] == year].sort_values(by="month_number"))
df_high_day = pd.concat(sorted_df_high_day).reset_index(drop=True).drop("month_number","columns")
df_high_day
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment