pandas - Map column names if data is same in two dataframes -
i have 2 pandas dataframes
df1 = b c 1 2 3 2 3 4 3 4 5
df2 = x y z 1 2 3 2 3 4 3 4 5 need map based on data if data same map column namesenter code here
output = col1 col2 x b y c z
i cannot find built-in function support this, hence loop on columns:
pairs = [] col1 in df1.columns: col2 in df2.columns: if df1[col1].equals(df2[col2]): pairs.append((col1, col2)) output = pandas.dataframe(pairs, columns=['col1', 'col2'])
Comments
Post a Comment