fightstarr20
fightstarr20

Reputation: 12628

Python pandas - Combine columns from different files

I have two CSV files. They actually have over 2 million records in each, but here's a simplified version:

File 1 :

col1
----
1
54
744
45
65

File 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. Is there something in Pandas I can use to achieve this?

Upvotes: 1

Views: 1749

Answers (1)

Stephen Kaiser
Stephen Kaiser

Reputation: 173

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

Upvotes: 4

Related Questions