Pandas无序类型中的透视表

2024-04-24 10:57:55 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个pandas数据帧(df),基本上如下所示

    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

我只想在此基础上创建一个简单的数据透视表来计算每个经理每天的平均得分。因此,我应该为每个经理的名字设置一个列。在

但是,当我跑的时候

^{pr2}$

我明白了

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

有了输出

<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)

为什么会出现这种类型的错误?它应该是字符串字段的一个简单轴,使用mean作为浮动字段上的自动聚合函数?在


Tags: columns数据pandasdfobjectmanagerjohn经理