My problem is next:
I have data frame A that looks like this:
1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1
and data frame B that look like this:
2 2 2
2 2 2
2 2 2
and I am trying to add B to A, so result should look like this:
1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1
1 1 1 3 3 3 1 1 1 1
1 1 1 3 3 3 1 1 1 1
1 1 1 3 3 3 1 1 1 1
1 1 1 1 1 1 1 1 1 1
At the moment I am extending data frame B with zeros so size it gets equal in size with data frame A ..... and just sum those two data frames.
Is there more elegant way of doing this? Also how I can add data frame B to the different parts of data frame A .... and for example will have result like this:
3 3 3 1 1 1 1 1 1 1
3 3 3 1 1 1 1 1 1 1
3 3 3 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1
Let me know if my question is not clear :)
Thanks.
CodePudding user response:
for the first one :
A.iloc[2:4, 2:4] = A.iloc[2:4, 2:4] B.to_numpy()
and for the second one :
A.iloc[0:2, 0:2] = A.iloc[2:4, 2:4] B.to_numpy()