Assign Small Dataframe To Large Dataframe By Row Indices
I am trying to assign a small dataframe to a large dataframe, both have the same columns. I couldn't find a duplicate on this. Pandas version 1.1.4 which I can't upgrade right now
Solution 1:
you can try values
attribute or to_numpy()
method:
df1.iloc[3:3+len(df2)]=df2.values
#OR
#df1.iloc[3:3+len(df2)]=df2.to_numpy()
Update:
other way:
df1.iloc[3:3+len(df2)]=df2.set_index(df1.iloc[3:3+len(df2)].index)
output of df1:
a
0 0
1 1
2 2
3 0
4 1
5 2
6 3
7 4
8 8
9 9
Post a Comment for "Assign Small Dataframe To Large Dataframe By Row Indices"