根据某列,将两个 dataframe 合并

时间:2021-11-28 03:33:25
import pandas as pd
import numpy as np
df1 = pd.DataFrame(np.array([['a', 5, 9], ['b', 4, 61], ['c', 24, 9]]),
columns = ['name', 'attr11', 'attr12'])
df2 = pd.DataFrame(np.array([['a', 5, 19], ['b', 14, 16], ['c', 4, 9]]),
columns = ['name', 'attr21', 'attr22'])
df3 = pd.DataFrame(np.array([['a', 15, 49], ['b', 4, 36], ['c', 14, 9]]),
columns = ['name', 'attr31', 'attr32'])
print(pd.merge(pd.merge(df1, df2, on = 'name'), df3, on = 'name'))

根据某列,将两个 dataframe 合并