简体   繁体   English

Python Pandas-合并来自不同文件的列

[英]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.

相关问题 尝试组合来自不同 excel 文件的列 - trying to combine columns from different excel files 如何 select 并根据 pandas python 中的特定条件组合不同的列? - How to select and combine different columns based on specific condition in pandas python? 如何在 Python 和 Pandas 中将不同的列组合成一个表 - How to combine different columns into one table in Python with Pandas 基于公共列 pandas 组合来自不同表的行 - Combine rows from different tables based on common columns pandas Python & Pandas:将列组合成日期 - Python & Pandas: Combine columns into a date Python/Pandas:比较来自不同长度的不同 CSV 文件的两个字符串列,并查找数据相同的位置 - Python/Pandas: Comparing two string columns from different CSV files that are of different lengths and finding where the data is the same Pandas/Python - 根据传入文件合并不同列上的文件 - Pandas/Python - Merging files on different columns based on incoming files 从 Pandas / Python 中的某一点开始合并所有列 - Combine all columns from a point onwards in Pandas / Python 来自不同列的Python Pandas字符串匹配 - Python Pandas String matching from different columns 比较季度数据:在 Python(Pandas) 中迭代以比较来自四个不同 excel 文件的多列,这些文件导入为 dataframe - Comparing quarterly data: Iteration in Python(Pandas) to compare multiple columns from four different excel files imported as dataframe
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM