Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Subtract two dataframe with the same name different index

There's two dataframes, all the colnames are the same but the index is different. I've tried several ways but I've been getting NaN. I'm guessing it is because it's trying to match the index but I am stuck.

I've tried:

df1.ix['Norm']-df2.ix['Norm']
df1 - df2.ix['Norm']
df1.astype(float) - df2.astype(float)

would like something like this

df1 - df2[df1.column.names]
like image 747
hammies Avatar asked Mar 21 '18 17:03

hammies


1 Answers

When you don't want index-aligned arithmetic, get rid of the indexes. You can subtract the numpy arrays to the same effect:

(df1.values - df2[df1.column.names].values)
like image 126
cs95 Avatar answered Sep 18 '22 17:09

cs95