pandas 合并操作 append处理重复项
import pandas as pd df1 = pd.DataFrame({'lkey': ['foo', 'bar', 'baz','foo'], 'value': [1, 2, 3,5]}) df2 = pd.DataFrame({'rkey': ['foo', 'bar', 'baz','foo'], 'value': [5, 6, 7,8]})
df1 = df1.rename(columns={'lkey':'rkey'}) df1 = df1.append(df2).reset_index(drop=True) df1.groupby('rkey').sum()
3步走
rename- append --groupby