2

I've got a pandas dataframe (df) that basically looks like the following

    TestDate            Manager     Score
0   2015-06-05 00:00:00 Jane Smith  5.000000
1   2015-06-05 00:00:00 John Doe    4.875000
2   2015-06-05 00:00:00 Jane Doe    4.428571
3   2015-06-05 00:00:00 John Doe    4.000000
4   2015-06-07 00:00:00 Josh Smith  3.500000
.....(~250 rows)

df.dtypes()
TestDate                 datetime64[ns]
Manager                  object
Score                    float64
dtype: object

I just want to create a simple pivot table on this to calculate the average score for each manager for each day. As such, I should have a column for each manager name.

However, when I run

df.pivot('TestDate', 'Manager', 'Score')

I get

TypeError: unorderable types: int() <= NoneType()

With the output

<class 'pandas.core.frame.DataFrame'>
DatetimeIndex: 11 entries, 2015-06-05 00:00:00 to 2015-06-24 00:00:00
Data columns (total 11 columns):
John Doe           4  non-null values
Jane Doe           4  non-null values
....
dtypes: float64(11)

Why am I getting this type error? It should be a simple pivot off of a string field using mean as the automatic aggregate function on a float field?

John
  • 1,405
  • 2
  • 14
  • 21

1 Answers1

1

you can try with pivot_table

df.pivot_table(values='Score', index='TestDate', columns='Manager', aggfunc='mean')
steboc
  • 1,161
  • 1
  • 7
  • 17
  • Thanks. So pivot and pivot_table do work in creating appropriate output. But I'm still getting the unorderable types error message. – John Jun 30 '15 at 18:56