No numeric types to aggregate - change in groupby() behaviour?

前端 未结 2 553
借酒劲吻你
借酒劲吻你 2020-12-03 04:06

I have a problem with some groupy code which I\'m quite sure once ran (on an older pandas version). On 0.9, I get No numeric types to aggregate errors. Any ideas?

2条回答
  •  醉梦人生
    2020-12-03 04:43

    How are you generating your data?

    See how the output shows that your data is of 'object' type? the groupby operations specifically check whether each column is a numeric dtype first.

    In [31]: data
    Out[31]: 
    
    DatetimeIndex: 2557 entries, 2004-01-01 00:00:00 to 2010-12-31 00:00:00
    Freq: <1 DateOffset>
    Columns: 360 entries, -89.75 to 89.75
    dtypes: object(360)
    

    look ↑


    Did you initialize an empty DataFrame first and then filled it? If so that's probably why it changed with the new version as before 0.9 empty DataFrames were initialized to float type but now they are of object type. If so you can change the initialization to DataFrame(dtype=float).

    You can also call frame.astype(float)

提交回复
热议问题