Python 如何将日期分组为熊猫

Python 如何将日期分组为熊猫,python,python-3.x,pandas,pandas-groupby,python-datetime,Python,Python 3.x,Pandas,Pandas Groupby,Python Datetime,我有一个df,它是由一列组成的,它的数据代表了几年内每天的平均温度。考虑到一年有365天,我想知道如何获得每天的最大值,并获得类似于以下内容的df: Datos 2015-01-01 58 2015-01-02 42 2015-01-03 41 2015-01-04 13 2015-01-05 6 ... ... 2020-06-18 49 2020-06-19 41 2020-06-20 23 2020-06-21 39 2020-06-22 22 200

我有一个df,它是由一列组成的,它的数据代表了几年内每天的平均温度。考虑到一年有365天,我想知道如何获得每天的最大值,并获得类似于以下内容的df:

    Datos
2015-01-01  58
2015-01-02  42
2015-01-03  41
2015-01-04  13
2015-01-05  6
...     ...
2020-06-18  49
2020-06-19  41
2020-06-20  23
2020-06-21  39
2020-06-22  22

2000 rows × 1 columns
请原谅我的无知,非常感谢您的帮助。

新建一个专栏:

        Datos
1   40
2   50
3   46
4   8
5   26
...     ...
361     39
362     23
363     23
364     37
365     25

365 rows × 1 columns
然后

您可以这样做:

df.groupby("day of year").max()
df.groupby("day of year").max()
df['Date'] = pd.to_datetime(df['Date'])
df = df.groupby(by=pd.Grouper(key='Date', freq='D')).max().reset_index()
df['Day'] = df['Date'].dt.dayofyear
print(df)

           Date  Temp  Day
0    2015-01-01  58.0    1
1    2015-01-02  42.0    2
2    2015-01-03  41.0    3
3    2015-01-04  13.0    4
4    2015-01-05   6.0    5
...         ...   ...  ...
1995 2020-06-18  49.0  170
1996 2020-06-19  41.0  171
1997 2020-06-20  23.0  172
1998 2020-06-21  39.0  173
1999 2020-06-22  22.0  174