Last active
September 7, 2022 11:20
-
-
Save ki-chi/6e88c015569731f13c9a100795d303cd to your computer and use it in GitHub Desktop.
coalesce function by pandas
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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