Question: I have DataFrame *x* and I would like to replace one column with Series *y*

```
x = DataFrame([[1,2],[3,4]], columns=['C1','C2'], index=['a','b'])

   C1  C2
a   1   2
b   3   4

y = Series([5,6,7], index=['a','b','c'])

a    5
b    6
c    7

```

Simple replacement works fine but keeps original index of DataFrame

```
x['C1'] = y

   C1  C2
a   5   2
b   6   4

```

I need to have union of indeces of *x* and *y*. One solution would be to reindex before replacement

```
x = x.reindex(x.index.union(y.index), copy=False)
x['C1'] = y

   C1   C2
a   5  2.0
b   6  4.0
c   7  NaN

```

Is there simpler way?

Answer: 
### [`combine_first`](https://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.combine_first.html)

Turn `y` into a `DataFrame` first with `to_frame`

```
y.to_frame('C1').combine_first(x)

   C1   C2
a   5  2.0
b   6  4.0
c   7  NaN

```

---

### [`align`](https://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.align.html) and `assign`

Use `align` to... align the indices

```
x, y = x.align(y, axis=0)

x.assign(C1=y)

   C1   C2
a   5  2.0
b   6  4.0
c   7  NaN

```
You can use `concat` but you will have to fix the column names, i.e.

```
import pandas as pd
pd.concat([x.loc[:, 'C2'], y], axis = 1)

```

which gives,

> 
> 
> ```
>     C2  0
> a  2.0  5
> b  4.0  6
> c  NaN  7
> 
> ```
> 
>