0

I have a dataframe like this input dataframe

And I want the output to be like:

output

I have gone through some similar problems, which uses table_pivot method to convert column vales to column and doing aggregation for the values. But that requirement is not suiting my problem definition.

Being new to pandas dataframe, having hard time to understand how to get this output.

Any suggestions would help me.

richa verma
  • 247
  • 2
  • 13
  • Can you add your `pivot_table` solution? Because I think here should working well. – jezrael Aug 17 '20 at 08:51
  • Also there are some error? Please add to question. – jezrael Aug 17 '20 at 08:51
  • df = pd.pivot_table(df, index=['flat', 'CurrentBill', 'CurrentPay', 'forecastedBill', 'forecastedPay'], columns=['year']) – richa verma Aug 17 '20 at 08:55
  • error: pandas.core.base.DataError: No numeric types to aggregate – richa verma Aug 17 '20 at 08:56
  • 1
    Try `df = pd.pivot_table(df, index=['flat', 'CurrentBill', 'CurrentPay'], values=['forecastedBill', 'forecastedPay'], columns=['year'])` and then flatten values `df.columns = [f'{a}{b}' for a,b in df.columns]` – jezrael Aug 17 '20 at 08:57

0 Answers0