I've following dataframes.
import pandas as pd
from pprint import pprint
df1 = pd.DataFrame(columns=["A", "B"])
df1["A"] = [1, 2]
df1["B"] = ["A", "B"]
df2 = pd.DataFrame(columns=["A", "C"])
df2["A"] = [3, 4]
df2["C"] = ["C", "D"]
df3 = pd.DataFrame(columns=["A", "C"])
df3["A"] = ["E", "F"]
df3["C"] = [0.1, 0.2]
I want to merge all three dataframes into single dataframe. Expected Output:
df
A B C D
1 A
2 B
3 C
4 D
E 0.1
F 0.2
I tried using merge function . It appends only 2 dataframes and also appends characters to column names, which I don't intend to do.
df = df1.merge(df2, left_on='A', right_on='C')
I'd like to know if there is an alternative way or in build function to do this.
df3. Should bedf3 = pd.DataFrame(columns=["B", "D"]) df3["B"] = ["E", "F"] df3["D"] = [0.1, 0.2]