简体   繁体   English

合并 2 个 CSV 没有公共列的文件

[英]Merge 2 CSV files with no common column

I have 2 csv files( 2 million each) with below structure我有 2 个 csv 个文件(每个 200 万个),结构如下

 first.csv h1,h2 2,3 4,5

 second.csv h3,h4 5,6 7,8

I want to merge these 2 csv index wise column like below我想像下面这样合并这 2 个 csv 索引列

 merged.csv h1,h2,h3,h4 2,3,5,6 4,5,7,8

You might be looking for the pandas.concat() function (see here ).您可能正在寻找pandas.concat() function(参见此处)。 Here is an example:这是一个例子:

import pandas as pd

df1 = pd.DataFrame({'A':[0,0,1,1,2],'B':[3,2,5,3,5]})
df2 = pd.DataFrame({'C':[0,0,1,1,2],'D':[-1,20,-2,33,17]})

df3 = pd.concat((df1,df2),axis=1)

df3.to_csv('myFile.csv')

You just have to replace df1 and df2 by your csv files using the pandas.read_csv function ( here ).您只需使用pandas.read_csv function( 此处)将 df1 和 df2 替换为您的 csv 文件。

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

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