How to assign columns while ignoring index alignment
pandas, python
Solution
The simplest way I can think of to get `pandas` to ignore the indices is to give it something without indices to ignore. Starting from
>>> x = pd.DataFrame({"foo": [10,20,30]},index=[1,2,0])
>>> y = pd.DataFrame({"bar": [33,11,22]},index=[0,1,2])
>>> x
foo
1 10
2 20
0 30
>>> y
bar
0 33
1 11
2 22
We have the usual aligned approach:
>>> x["foo"] = y["bar"].order(ascending=False)
>>> x
foo
1 11
2 22
0 33
Or an unaligned one, by setting `x["foo"]` to a list:
>>> x["foo"] = y["bar"].order(ascending=False).tolist()
>>> x
foo
1 33
2 22
0 11
Problem
Say I have two dataframes `x` and `y` in Pandas, I would like to fill in a column in `x` with the result of sorting a column in `y`. I tried this: ``` x['foo'] = y['bar'].order(ascending=False) ``` but it didn't work, I suspect because Pandas aligns indices between `x` and `y` (which have the same set of indices) during the assignment How can I have Pandas fill in the `x['foo']` with another column from another dataframe ignoring the alignment of indices?