您可以使用简单的数学公式将一个月压缩为一个季节,例如:
>>> [month%12 // 3 + 1 for month in range(1, 13)][1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 1]
因此,对于使用向量运算的用例(@DSM点数):
>>> temp2.dt.month%12 // 3 + 11 32 33 34 45 46 47 48 4Name: id, dtype: int64

您可以使用简单的数学公式将一个月压缩为一个季节,例如:
>>> [month%12 // 3 + 1 for month in range(1, 13)][1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 1]
因此,对于使用向量运算的用例(@DSM点数):
>>> temp2.dt.month%12 // 3 + 11 32 33 34 45 46 47 48 4Name: id, dtype: int64