小编Rob*_*tti的帖子

在python中合并数据帧时重复的行

我目前正在使用外连接合并2个数据帧,但在合并之后,我看到所有行都是重复的,即使我合并的列包含相同的值.详细地:

list_1 = pd.read_csv('list_1.csv')
list_2 = pd.read_csv('list_2.csv')

merged_list = pd.merge(list_1 , list_2 , on=['email_address'], how='inner')
Run Code Online (Sandbox Code Playgroud)

具有以下输入和结果:

LIST_1:

email_address, name, surname
john.smith@email.com, john, smith
john.smith@email.com, john, smith
elvis@email.com, elvis, presley
Run Code Online (Sandbox Code Playgroud)

list_2:

email_address, street, city
john.smith@email.com, street1, NY
john.smith@email.com, street1, NY
elvis@email.com, street2, LA
Run Code Online (Sandbox Code Playgroud)

merged_list:

email_address, name, surname, street, city
john.smith@email.com, john, smith, street1, NY
john.smith@email.com, john, smith, street1, NY
john.smith@email.com, john, smith, street1, NY
john.smith@email.com, john, smith, street1, NY
elvis@email.com, elvis, presley, street2, LA
elvis@email.com, elvis, presley, street2, LA
Run Code Online (Sandbox Code Playgroud)

我的问题是,不应该这样吗?

merged_list(我希望如何:D): …

python merge python-2.7 python-3.x pandas

10
推荐指数
2
解决办法
3万
查看次数

标签 统计

merge ×1

pandas ×1

python ×1

python-2.7 ×1

python-3.x ×1