Python/Panda-根据连接表/csv合并csv [英] Python/Panda - merge csv according to join table/csv

查看:245
本文介绍了Python/Panda-根据连接表/csv合并csv的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对2个csv文件的合并有问题.我有2个文件,这些数据包含多列数据,包括唯一ID和另一个将文件1的ID映射到文件2的ID的文件.所以我基本上有一个.

I have a problem regarding the merge of 2 csv files. I have 2 files containing multiples columns of data including unique id's and another file that maps those Id's of file 1 to an id of file 2. So I have basically a .

现在,我要创建一个新的csv文件,并根据连接csv中的id映射将文件1和2中的数据连接起来.

Now I want to create a new csv file with data from file 1 and 2 joined according to the id mappings in my join csv.

在这里举一个例子,我的数据看起来如何:

Heres an example how my data looks:

CSV1-客户

ID, Name, Lastname
1,  Peter, Pan
2,  Hank,  Tank

CSV2-地址

ID, Street, State
5,  Mainstr, US
7,  H Blvd,  DE

加入CSV:

CID, AID
1,   5
2,   7

我想要什么:

ID, Name, Lastname, Street, State
    1,  Peter, Pan,  Mainstr, US
    2,  Hank,  Tank  H Blvd,  DE

我非常感谢您提供帮助或举个例子,说明如何使用python/panda解决此问题.

I would really appreciate help or an example how I can solve this issue with python / panda.

推荐答案

使用 merge ,最后通过 查看全文

登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆