Dictionaries x.update(y) for pandas DataFrames?
Question: I am sitting in front of a probably very simple problem. I have two pandas
DataFrames with some common Indices, like so:

    
    
    import pandas as pd
    x = pd.DataFrame(index=[1, 2, 3, 4],
                     data={'d': [5, 5, 5, 5]})
    y = pd.DataFrame(index=[3, 4, 5, 6],
                     data={'d':  [6, 6, 6, 6]})
    

What i now want to do is to update `x` by `y`. This means to me three things:

  1. The indices `1, 2` are only in `x` and not in `y`. Keep the values from `x`.
  2. The indices `3, 4` are common indices in `x` and `y`. Update the values with the new info from `y`.
  3. The indices `5, 6` are only in `y`. Add them with their respective values to `x`.

In total, the result should look like this:

    
    
    x = pd.DataFrame(index=[1, 2, 3, 4, 5, 6],
                     data={'d': [5, 5, 6, 6, 6, 6]})
    

Thinking in terms of python dictionaries, I tried `x.update(y)`, which did
steps 1. and 2., but doesn't do step 3. I am confident that this is a one-
liner, but i just cannot find it.

## Addendum

I mentioned dictionaries (with the index as key), the approach there would
look like this:

    
    
    a = {1: 5,
         2: 5,
         3: 5,
         4: 5}
    
    b = {3: 6,
         4: 6,
         5: 6,
         7: 6}
    
    a.update(b)
    

It returns:

    
    
    {1: 5, 2: 5, 3: 6, 4: 6, 5: 6, 7: 6}
    


Answer: You can call `combine_first` but using y as the destination, this will
overwrite the values from x that are missing from y:

    
    
    In [75]:
    
    y.combine_first(x)
    Out[75]:
       d
    1  5
    2  5
    3  6
    4  6
    5  6
    6  6
    

you can't use [`update`](http://pandas.pydata.org/pandas-
docs/stable/generated/pandas.DataFrame.update.html#pandas.DataFrame.update) to
achieve what you want as this only updates the existing values:

    
    
    In [79]:
    
    x.update(y)
    x
    Out[79]:
       d
    1  5
    2  5
    3  6
    4  6
    

