【发布时间】:2019-06-20 08:27:43
【问题描述】:
我有两个想要合并的 csv 文件,如下所示 - 或多或少使用第一列 ID_ 作为唯一标识符,并将 AMT 列附加到最终文件中的新行。
CSV1
ID_ CUSTOMER_ID_ EMAIL_ADDRESS_
1090 1 example1@example.com
1106 2 example2@example.com
1145 3 example3@example.com
1206 4 example4@example.com
1247 5 example5@example.com
1254 6 example6@example.com
1260 7 example7@example.com
1361 8 example8@example.com
1376 9 example9@example.com
CSV2
ID_ AMT
1090 5
1106 5
1145 5
1206 5
1247 5
1254 65
1260 5
1361 10
1376 5
这是我在最终文件中寻找的内容:
ID_ CUSTOMER_ID_ EMAIL_ADDRESS_ AMT
1090 1 example1@example.com 5
1106 2 example2@example.com 5
1145 3 example3@example.com 5
1206 4 example4@example.com 5
1247 5 example5@example.com 5
1254 6 example6@example.com 65
1260 7 example7@example.com 5
1361 8 example8@example.com 10
1376 9 example9@example.com 5
我已尝试尽可能多地修改以下内容,但无法获得我想要的内容。真的坚持这一点 - 不知道我还能做什么。非常感谢任何和所有的帮助!
join -t, File1.csv File2.csv
此示例中显示的数据包含选项卡,但我的实际文件是前面提到的 CSV,并将包含逗号作为分隔符。
【问题讨论】:
-
我在我的 linux 机器上运行了你的
join命令并得到了正确的输出。你在运行什么系统?我能想到的可能是您的join版本不同,或者换行符有误。
标签: python regex csv merge two-columns