0

I have two files, the first one is called first.csv, and looks like this:

header1,header2
1,a
2,b

The second file is called second.csv, and looks like this:

header1,header2,header3,header4,header5
1,a,m,n,o
2,b,p,q,r

My Goal is to append a new row in second.csv if any new row added in first.csv

And I need a result like:

first.csv

header1,header2
1,a
2,b
3,c

then

second.csv

header1,header2,header3,header4,header5
1,a,m,n,o
2,b,p,q,r
3,c,-,-,-,-

Thanks in Advance

4
  • Did you try using joins in pandas? Commented Jan 18, 2020 at 16:01
  • Sorry, I'm not aware of that. Can you write snippet for that? @dper Commented Jan 18, 2020 at 16:07
  • Welcome to SO. This isn't a discussion forum or tutorial. Please take the tour and take the time to read How to Ask and the other links found on that page. Invest some time with the Tutorial practicing the examples. It will give you an idea of the tools Python offers to help you solve your problem. Commented Jan 18, 2020 at 16:08
  • I'm voting to close this. Stack Overflow is not the place to have others write all your code for you, particularly when there is no evidence of even the tiniest amount of research. Commented Jan 18, 2020 at 16:54

1 Answer 1

2

You can try using the joins :

pd.merge(first, second, how='left', on=None, left_on=None, right_on=None,
         left_index=False, right_index=False, sort=True,
         suffixes=('_x', '_y'), copy=True, indicator=False,
         validate=None)

This might be more intuitive if you go through this post, It might provide you a clear idea of how to actually perform the joins ...

https://pandas.pydata.org/pandas-docs/stable/user_guide/merging.html

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.