Search This Blog

Showing posts with label pandas data frames updates. Show all posts
Showing posts with label pandas data frames updates. Show all posts

Friday, November 10, 2017

Pandas Data frame update update


Pandas data frame update should be one of the most useful functions.





DataFrame.update(otherjoin='left'overwrite=Truefilter_func=Noneraise_conflict=False)[source]
Modify DataFrame in place using non-NA values from passed DataFrame. Aligns on indices


https://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.update.html

Pandas dataframe merge with update data

Pandas dataframe merge with update data
print (pd.concat([df1, df2]).drop_duplicates('date', keep='last'))
date value
0 2017-01-01 1
1 2017-01-02 1
2 2017-01-03 1
0 2017-01-04 2
1 2017-01-05 2
2 2017-01-06 2
3 2017-01-07 2
4 2017-01-08 2
You can use concat with drop_duplicates by column date and keep last values:
Concat works, but drop_dublicates('ID', keep='last') does not.