简体   繁体   English

我如何在python中外部联接两个不同文件的两个未命名列

[英]How can I outer join two unnamed columns of two different files in python

I have two files File 1 and 2. I want to perform outer join on first column of both of them. 我有两个文件文件1和2。我想在两个文件的第一列上执行外部联接。 But, the problem is that both of the files have unnamed columns. 但是,问题在于两个文件都有未命名的列。

So, is there any way I can apply outer join on unnamed columns? 因此,有什么方法可以将外部联接应用于未命名的列?

Any help will be appreciated. 任何帮助将不胜感激。 Thanks in Advance. 提前致谢。

File 1: 文件1:

0    6    7
1    4    9
2    0    3
3    5    8

File 2: 档案2:

0    7    3
1    3    9
2    6    2
3    8    0

Expected Output: 预期产量:

0    6    7    7    3
1    4    9    3    9
2    0    3    6    2
3    5    8    8    0

IIUC you want to concatenate your files horizontally: 您要水平连接文件的IIUC:

d1 = pd.read_csv(filename1, header=None)
d2 = pd.read_csv(filename1, header=None)

pd.concat([d1, d2], axis=1).to_csv(r'/path/to/result.csv', index=False)

PS you may want to specify a correct separator sep='???' PS,您可能需要指定正确的分隔符sep='???' (default is sep=',' ) when calling pd.read_csv() and .to_csv() (默认为sep=',' )调用pd.read_csv().to_csv()

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

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