Reputation: 75
So I have this dataframe(displayed only a part of it)
name CEMS emit consent Ht CEMS-4 61 50 Ht CEMS-5 33.75 50 Ld CEMS-1 21.625 100 Sh CEMS-3 71.4 100
Now, what I have to do is find the mean of emit and then subtract it from consent of a particular CEMS
What I am doing is
mod = df.consent.iloc[0] eMean = df['emit'].mean() eMean = ("%.2f" % eMean) diff1 = eMean - mod diff = float(diff1)/float(mod)
and I am getting this error
diff1 = eMean - mod TypeError: ufunc 'subtract' did not contain a loop with signature matching types dtype('S21') dtype('S21') dtype('S21')
Help me out in this please
Upvotes: 1
Views: 64
Reputation: 862511
I think need to remove assign to variable eMean
in eMean = ("%.2f" % eMean)
and if necessary cast values to floats:
mod = float(df.consent.iloc[0])
eMean = df['emit'].astype(float).mean()
print ("%.2f" % eMean)
diff1 = eMean - mod
diff = diff1 / mod
Upvotes: 1