简体   繁体   English

将一个 CSV 文件中的列添加到另一个 CSV 文件

[英]Adding column from one CSV file to another CSV file

I have 2 CSV files that I need to merge together based on a key i created ( the purpose was to mask ID's then join the ids on the key later ) I can do this in SSIS, but im have an error runing the batch script from my python script (something to do with SSIS not running packages outside SSIS. Working with software team to fix ) but in the mean time I would like to just have it working for a demo.我有 2 个 CSV 文件,我需要根据我创建的密钥合并在一起(目的是屏蔽 ID,然后稍后加入密钥上的 ID)我可以在 SSIS 中执行此操作,但是我在运行批处理脚本时出错我的 python 脚本(与 SSIS 没有在 SSIS 之外运行包有关。与软件团队合作修复)但同时我想让它只用于演示。

Is this possible in Python?这在 Python 中可能吗?

File 1:
input_id multiple columns --->
1
2
3
File 2:
input_id  ID
1         1234
2         1235
3         1236

output:
input_id multiple columns ---> ID
1                              1234
2                              1235
3                              1236 
a = pd.read_csv("import.csv")

b = pd.read_csv("entity_ids.csv")

merge = a.merge(b, how='left', on='input_id')

merge.to_csv("test2.csv", index = False)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM