When you use
df.loc['A', :] = df_
Pandas is trying to align the df_ index with the sub-DataFrame df index. However, at the point in the code where the alignment is performed, the sub-DataFrame has MultiIndex , and not the only index that you see as a result of df.loc['A', :] .
Thus, alignment is not performed because df_ has a single index, not MultiIndex, which is needed. To make sure the df_ index df_ indeed a problem, please note that
ix_ = pd.MultiIndex.from_product([['A'], ['a', 'b', 'c', 'd']]) df_.index = ix_ df.loc['A', :] = df_ print(df)
succeeds yielding to something like
A a 0.229970 0.730824 0.784356 b 0.584390 0.628337 0.318222 c 0.257192 0.624273 0.221279 d 0.787023 0.056342 0.240735 B a NaN NaN NaN b NaN NaN NaN c NaN NaN NaN d NaN NaN NaN
Of course, you probably don't want to create a new MultiIndex every time you want to assign a block of values. Instead, to get around this alignment problem, you can use the NumPy array as the destination value:
df.loc['A', :] = df_.values
Since df_.values is a NumPy array, and the array has no index, no alignment is performed and the assignment gives the same result as above. This trick of using NumPy arrays when you don't want to align indexes is applied in many situations when using Pandas.
Note also that array-by-NumPy-array can also help you perform more complex assignments, for example, for strings that are not adjacent:
idx = pd.IndexSlice df.loc[idx[:,('a','b')], :] = df_.values
gives
In [85]: df Out[85]: 1st 2nd 3rd A a 0.229970 0.730824 0.784356 b 0.584390 0.628337 0.318222 c NaN NaN NaN d NaN NaN NaN B a 0.257192 0.624273 0.221279 b 0.787023 0.056342 0.240735 c NaN NaN NaN d NaN NaN NaN
eg.