Skip to content

Instantly share code, notes, and snippets.

@ki-chi
Last active September 7, 2022 11:20
Show Gist options
  • Save ki-chi/6e88c015569731f13c9a100795d303cd to your computer and use it in GitHub Desktop.
Save ki-chi/6e88c015569731f13c9a100795d303cd to your computer and use it in GitHub Desktop.
coalesce function by pandas
import pandas as pd
def coalesce(df: pd.DataFrame, *args) -> pd.Series:
return df[list(args)].bfill(axis=1).iloc[:, 0]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment