Let
df
be some dataframe;X
be a tuple containing the numerical indices of some ofdf
's columns;df0
be the sub-dataframe ofdf
given bydf.iloc[:, X]
; anddf1
be some transform ofdf0
such thatlen(df1)
equalslen(df0)
, anddf1.columns
equalsdf0.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 NaN
s, even though there are no NaN
s 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.