Zanam Zanam - 23 days ago 9
Python Question

Intersection of multiple pandas dataframe

I have a number of dataframes in a list as:

frameList = [df1,df2,..,df100]


Each dataframe is made of first column as
"DateTime"
and second column is
"Temperature"
.

How do I find common temperature column from all the dataframes in the list by intersecting it on
DateTime
. Using pandas
merge
is not going to work as I will have to redo pairwise intersection multiple times.

Edit:

Changed the column heading to only intersection as I think word
merge
was confusing.

Edit:

My final output should have
DateTime
as first column followed by Temperature from df1, Temperature from df2, Temperature from df3, .., Temperature from df100.

Answer

you can try using reduce functionality in python..something like this

dfs = [df0, df1, df2, dfN]
df_final = reduce(lambda left,right: pd.merge(left,right,on='DateTime'), dfs)
Comments