mercredi 23 novembre 2016

Pandas conditional division, series by list

I'm trying to apply an if condition to a pandas series and subsequently apply a division operation to another series in the same dataframe against an integer value from a list. The logic I'm trying to apply is as follows: if the household category in the hh_cat series matches the current value of i then divide the consumption series by the relevant total of the family consumption sub-group given by the list value family_con[i-1]

for i in hh_cat:
   result = mod_df[(mod_df["hh_cat"]==i)].div()["consumption"](family_con[i-1])


TypeError                                 Traceback (most recent call last)
<ipython-input-120-219bc0ce5a07> in <module>()
  1 for i in hh_cat:
----> 2     result = mod_df[(mod_df["hh_cat"]==i)].div()["consumption"] (family_con[i-1])

TypeError: f() takes at least 2 arguments (1 given)

Aucun commentaire:

Enregistrer un commentaire