I have a LONG list of dataframes (with many columns ...) like so:
DF1
nameOne total_one total_two nameTwo nameThree ...
0 nn1 2 3 nn4 nn7
1 nn2 2 3 nn5 nn8
2 nn3 2 3 nn6 nn9
DF2
nameOne total_one total_two nameTwo nameThree. ....
0 nn1 4 6 nn4 nn7
1 nn2 4 6 nn5 nn8
2 nn3 4 6 nn6 nn9
What I want the result to look like:
RESULT_DF
nameOne total_one total_two nameTwo nameThree. ....
0 nn1 6 9 nn4 nn7
1 nn2 6 9 nn5 nn8
2 nn3 6 9 nn6 nn9
In other words, I just want to add the number columns.
I tried doing this: DF1.add(DF2, fill_value=0)
But I get this error: TypeError: unsupported operand type(s) for +: 'int' and 'str'
For brevity, here I only showed one Str column. But I have many more STR columns, and many more int/float columns.
Explanation: Please note this is not the same as THIS question because I mentioned that I have multiple string fields.
nameOneas the indexcols = ['total_one', 'total_two']; df = df1.copy(); df[cols] = df1[cols] + df2[cols]