Advertisements
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
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