0

I am trying to split a dataframe of 4 columns, similar as the one above:

id_inf  id_prov  year      total
     9      676  2007     600.00
     9      676  2008     150.00
     9    34957  2007      18.75
     9    34957  2008      12.50
     9   185304  2007     296.94
     9   189095  2009   12048.90
    54       54  2015       6.54
    54    12088  2009      63.00
    ..      ...   ...        ...

into a dataframe that the values of each year is separated in different columns. I need a dataframe that looks like this:

id_inf  id_prov   t_2007  t_2008   t_2009  ... t_2015  
     9      676   600.00  150.00      NaN  ...    NaN      
     9    34957    18.75   12.50      NaN  ...    NaN
     9   185304   296.94     NaN  2048.90  ...    NaN 
    54       54      NaN     NaN      NaN  ...   6.54
    54    12088      NaN     NaN    63.00  ...    NaN
    ..      ...      ...     ...      ...  ...    ...

I've been trying to use pivot tables, to get something similar but it isn't working as I need. Can somebody can give me any guidance on how can I achieve this?.

Thanks

PAstudilloE
  • 659
  • 13
  • 24

0 Answers0