inaMinute
inaMinute

Reputation: 585

how to append a dataframe to existing csv file and remove the duplicates data

i have a dataframe data and csv data as following enter image description here

enter image description here

i want to append the dataframe data to the csv file.however ,there are duplicates between the two data.so how to remove the duplicates and append new data to csv file.

Upvotes: 5

Views: 4679

Answers (1)

jezrael
jezrael

Reputation: 863701

I think you need read_csv with DataFrame.append, then drop_duplicates and last to_csv:

pd.read_csv('file').append(df).drop_duplicates().to_csv('file')

Upvotes: 6

Related Questions