Menu
  • HOME
  • TAGS

Python Pandas: Spread total values in dataframe based on percentages back to categories

python,pandas,spatial-data-frame

Don't know if you can do this more elegantly, but you could do it like this: >>> df_tot = df[df['Cat'] == 'tot cat'].reindex(index=df.index, method='backfill') >>> for x in df.columns: if 'val' in x: df[x] = df['Percentage'] * df_tot[x] / 100 Country State City Cat Total_amount Percentage val1 val2 val3 val4...