[英]Python pandas - Combine columns from different files
I have two CSV files. 我有两个CSV文件。 They actually have over 2 million records in each, but here's a simplified version:
实际上每个记录中都有超过200万条记录,但这是一个简化的版本:
File 1 : 文件1:
col1
----
1
54
744
45
65
File 2 : 文件2:
col2
----
sdf
322
d3
d
2
What is the quickest way of combining the two of these to end up with the following? 将两者结合起来以得到以下结果的最快方法是什么?
col1 | col2
-------------
1 | sdf
54 | 322
744 | d3
45 | d
65 | 2
I would usually use Excel or similar but the dataset is too large to load. 我通常会使用Excel或类似工具,但数据集太大而无法加载。 Is there something in Pandas I can use to achieve this?
熊猫中有什么我可以用来实现的吗?
import pandas as pd
df1 = pd.read_csv("csv1")
df2 = pd.read_csv("csv2")
result = pd.concat([df1, df2], axis=1)
This should do the trick 这应该可以解决问题
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.