1

I'm trying to make a heat map using a weighted average percentage. I was trying to do something similar to using a calculated field in a pivot table in excel, but wound up with two grouped data frames with the same index and columns. The grouping was done by two sets of predetermined buckets, one of which I unstacked to be the column headers (eg. [0,10,20,50,100] and [0,1,2,5,10]).

    df7 = df5.groupby(['SomeBuckets','MoreBuckets']).sum().astype(float).unstack(['MoreBuckets'])
    df8 = df6.groupby(['SomeBuckets','MoreBuckets']).sum().astype(float).unstack(['MoreBuckets'])

I'm not sure how to divide the two literally cell by cell, is there a way to do this? I tried

    df9 = df7.truediv(df8,axis=0,fill_value='')

but all that gave me was a dtype error, could not convert string to float.

JD2015
  • 155
  • 1
  • 2
  • 12
  • 1
    Do you have a small sample of data? – Alexander Mar 15 '16 at 21:27
  • It looks like the conversion to float `.astype(float)` failed in the previous step. You should use [`pandas.to_numeric()`](http://pandas.pydata.org/pandas-docs/version/0.17.0/generated/pandas.to_numeric.html) instead, which is the new and preferable method, and lets you coerce the result in case of failure. – IanS Mar 16 '16 at 09:11

0 Answers0