python - Pivot Tables in Pandas- Unorderable Types -
i've got pandas dataframe (df) looks 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 want create simple pivot table on calculate average score each manager each day. such, should have column each manager name.
however, when run
df.pivot('testdate', 'manager', 'score')
i get
typeerror: unorderable types: int() <= nonetype()
with output
<class 'pandas.core.frame.dataframe'> datetimeindex: 11 entries, 2015-06-05 00:00:00 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 getting type error? should simple pivot off of string field using mean automatic aggregate function on float field?
you can try pivot_table
df.pivot_table(values='score', index='testdate', columns='manager', aggfunc='mean')
Comments
Post a Comment