0

by using pandas, I'd like to find a way to replace some rows of df1 (outdated) with all rows of df2 (update of df1) based on column values (Date) + new possible rows df2 (part of the update) containing new dates under Date column.

Assumptions: Essentially, I'm talking about an incremental update of a dataframe that will happen periodically. E.g.:

  • week0=df1
  • week1: df1+df2(update)=df3
  • week2: df3+df4(update)=df5
  • week3: df5+df6(update)=df7

The columns are equal on both dataframes: date, name, surname, vendor, quantity

Any suggestion?

gidonof
  • 3
  • 2
  • Set the merging key as index and use `combine_first` – mozway Oct 22 '22 at 19:07
  • Can you merge both lists and then delete duplicates? pd.drop_duplicates. https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.drop_duplicates.html – Hu gePanic Oct 22 '22 at 19:09
  • Does this answer your question? [Python Pandas update a dataframe value from another dataframe](https://stackoverflow.com/questions/49928463/python-pandas-update-a-dataframe-value-from-another-dataframe) – Michael Delgado Oct 22 '22 at 19:48

0 Answers0