Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 14040

how to write a function with unknown number of input in python? [duplicate]

$
0
0

I would like to write a function keeping the common index of input dataframes. I could write it as follows for 2 dataframes:

def get_df_common_index(df1, df2):    common_index = df1.index.intersection(df2.index)    return df1.loc[common_index], df2.loc[common_index]

My question is how to make it a general function which can take multiple inputs and return dataframes accordingly? As if I could use it as follows:

df1, df2, df3, df4 = get_df_common_index(df1, df2, df3, df4)

Viewing all articles
Browse latest Browse all 14040

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>