本文主要是介绍pandas27 merge(数据库风格合并列名后缀实例)( tcy),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
# 实例4:重叠值列
# suffixes参数:字符串列表的元组,重叠列名后缀
left = pd.DataFrame({'k': ['K0', 'K1', 'K2'], 'v': [1, 2, 3]})
right = pd.DataFrame({'k': ['K0', 'K0', 'K3'], 'v': [4, 5, 6]})result = pd.merge(left, right, on='k')
result1 = pd.merge(left, right, on='k', suffixes=['_l', '_r'])left right result result1k v k v k v_x v_y k v_l v_r
0 K0 1 0 K0 4 0 K0 1 4 0 K0 1 4
1 K1 2 1 K0 5 1 K0 1 5 1 K0 1 5
2 K2 3 2 K3 6left = left.set_index('k')
right = right.set_index('k')
result = left.join(right, lsuffix='_l', rsuffix='_r')# left right v_l v_rv v k
k k K0 1 4.0
K0 1 K0 4 K0 1 5.0
K1 2 K0 5 K1 2 NaN
K2 3 K3 6 K2 3 NaN
这篇关于pandas27 merge(数据库风格合并列名后缀实例)( tcy)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!