Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Merge all files and grab particular column data

I have many files in a folder. Below is the sample one.

abc.csv

Seller Vaule
Hari 2
Om 12
Cat 0
Mat 14
John 0

Another table as –
bcd.csv

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Seller Vaule
Hari 0
Om 12
Cat 2
Mat 14
John 4

I have the same type csv files in my folder and I would like to merge all of them and keep the seller if its value = 0.

My expected output would be –

Final table –

Seller Vaule
Hari 0
Cat 0
John 0

>Solution :

concat and filter (for example with query), optionally dropping duplicates (drop_duplicates):

out = (pd.concat([abc, bcd]).query('Vaule == 0')
         .drop_duplicates(['Seller', 'Vaule']) # optional
      )

Output:

  Seller  Vaule
2    Cat      0
4   John      0
0   Hari      0
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading