Let
dfbe some dataframe;Xbe a tuple containing the numerical indices of some ofdf's columns;df0be the sub-dataframe ofdfgiven bydf.iloc[:, X]; anddf1be some transform ofdf0such thatlen(df1)equalslen(df0), anddf1.columnsequalsdf0.columns;
Hence df.iloc[:, X] has the same shape as df1.
I want to update the contents of the df.iloc[:, X] sub-dataframe by assigning df1 to it.
If I do the naive thing:
df.iloc[:, X] = df1
most of the updated columns (though not all, curiously enough) get filled with NaNs, even though there are no NaNs in df1.
I figure that this has to do with the indexing of df1 with respect to df, but couldn't find a solution. (One Hail-Mary-Pass thing I tried was setting df1.index = df.index, but it didn't work1.)
1Not surprising, since I don't know what I'm doing, though not for lack of trying. I've read the Pandas book, as well as several tutorials, blogs, etc., and some of the source code too, but working with Pandas remains somewhat Russian-roulette-ish for me.