import pandas as pd
import numpy as np
'''This is first dataframe'''
df1=pd.DataFrame({'fruit': ['apple', 'banana', 'orange']*3,'weight':['high','medium','low']*3
,'price': np.random.randint(0, 15, 9)})
'''This is first dataframe'''
df2=pd.DataFrame({'product': ['apple', 'orange', 'pine'] * 2,
'kilo': ['high', 'low'] * 3,
'price': np.random.randint(0, 15, 6)})
'''我要在两个数据帧上执行合并操作'''
merged=pd.merge(left_on=['fruit','weight'],right_on=['product','kilo'],how='inner',suffixes=
['_left','_right'])
'''它给出了一个我不明白为什么的类型错误'''
您还需要提供要合并的数据框。尝试这个:
输出:
您必须声明要合并的左右数据框:
输出: