2
$\begingroup$

Table 1

Table 2

I want to combine both CSV files based on Column1, also when combined each element of Column1 of both csv should match and also each row or Please suggest how to reorder Column1 according to another csv. In Jupyter Notebook Thank You!

$\endgroup$
2
$\begingroup$

You can try the below code to merge two file:

import pandas as pd
df1 = pd.read_csv(‘first.csv’)
df2 = pd.read_csv(‘second.csv’)
df = df1.merge(df2, on=‘Column1’)
| improve this answer | |
$\endgroup$
1
$\begingroup$

You can use inner join:

import pandas as pd
df1 = pd.read_csv('file1.csv')
df2 = pd.read_csv('file2.csv')
df = pd.merge(df1, df2, on="Column1", how="inner")
| improve this answer | |
$\endgroup$
1
$\begingroup$

There are many methods to connect two different kinds of datasets


  • Python Pandas - Merging/Joining
  • left − A DataFrame object.
  • right − Another DataFrame object.
  • on − Columns (names) to join on. ...
  • left_on − Columns from the left DataFrame to use as keys. ...
  • right_on − Columns from the right DataFrame to use as keys. ...
  • left_index − If True, use the index (row labels) from the left DataFrame as its join key(s).

Syntax

pd.merge(left, right, how='inner', on=None, left_on=None, right_on=None, left_index=False, right_index=False, sort=True)

Answer

pd.merge( firstDF, secondDF ,on='Column1')

For More Resources: Padas Data Merging/Joining Resourse

| improve this answer | |
New contributor
Vikas Ukani is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.