I'm sorry if this has been asked before but I wasn't sure how to word this question into a search.
I have 2 data frames with a year column and value column. I want to udpate the first data frame based on matching the year and update the value column according to which value is larger. Suppose the data frames look like this
>>> import pandas as pd
>>> x = [1999, 2000, 2001]
>>> y = [0, 0, 0]
>>> df1 = pd.DataFrame({'year': x, 'value': y})
>>> df1
year value
0 1999 0
1 2000 0
2 2001 0
>>> x2 = [1999, 2003, 2004]
>>> y2 = [5, 0, 0]
>>> df2 = pd.DataFrame({'year': x2, 'value': y2})
>>> df2
year value
0 1999 5
1 2003 0
2 2004 0
I want the updated data frame (df1) to look this. Is there a simple way to do this?
year value
0 1999 5
1 2000 0
2 2001 0
df1.value = df2.value