1

I have a data frame.

date           name     start_time_bin      skill set
2019-10-25     Joe       10am- 12am          C,Python
2019-10-25     Mark      10am- 12am          Java,Python
2019-10-25     Sara      12pm- 2pm          Java,Python
2019-10-26     Jim       12pm- 2pm           C,Python, scala
2019-10-26     Bob       >=2pm < 4pm         C,SQL

I'm trying to convert this dataframe into something like this using pivot.

Audit_date    10am- 12am   12pm- 2pm      >=2pm < 4pm  
2019-10-25       Joe          Sara            Nan
2019-10-25       Mark          Nan            Nan
2019-10-26       Nan           Jim            Bob

I tried using the following:

piv = new.pivot_table(index=['Audit_Date'], columns='start_time_bin', values='name')

I'm getting error as No numeric types to aggregate

Is there any other way to do this?

Shubham R
  • 7,382
  • 18
  • 53
  • 119

1 Answers1

0

If never duplicates per Audit_Date with start_time_bin then is possible use aggregation by first:

piv = new.pivot_table(index='Audit_Date', 
                      columns='start_time_bin', 
                      values='name', 
                      aggfunc='first')

Or if possible duplicates then aggregate by join:

piv = new.pivot_table(index='Audit_Date', 
                     columns='start_time_bin', 
                     values='name', 
                     aggfunc=', '.join)
jezrael
  • 822,522
  • 95
  • 1,334
  • 1,252
  • https://stackoverflow.com/questions/47152691/how-to-pivot-a-dataframe – ansev Nov 18 '19 at 10:23
  • 1
    No numeric types to aggregate: https://stackoverflow.com/questions/39229005/pivot-table-no-numeric-types-to-aggregate – ansev Nov 18 '19 at 10:29
  • @ansev https://stackoverflow.com/questions/58912146/pivot-on-non-numeric-types-pandas?noredirect=1#comment104086987_58912146 – jezrael Nov 18 '19 at 10:30