0
$\begingroup$

So I have one csv with 'films' in a database that have a unique ID

movie_title      | ID       | popularity
spider-man        unique ID   4.2
captain marvel    unique ID   9.9

Then about every week, I would like to update that popularity with a new one from another list of movies.

New movie list:

movie_title      | ID       | popularity
spider-man        unique ID   5.5
captain marvel    unique ID   7.4

How can I merge these two csv and output a new csv with only the value popularity updating? I have other values that also change over the week, but I just did popularity for simplicity. The unique ID must be in the new csv as well not only the changes; because, when I resubmit back to the database that is the only way that it will update with the ID.

The second list does not contain the ID's.

$\endgroup$

1 Answer 1

1
$\begingroup$

What you need is a pandas.DataFrame.update.

Use pandas.read_csv to read the csv file to a Pandas DataFrame, then do the update. Once you have made the update you can use pandas.DataFrame.to_csv to convert it back to a csv.

$\endgroup$

Your Answer

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