潘达斯数据框架的datetimeindex,按月和年对记录进行排序。

问题描述 投票:1回答:1

land_temps 以日期时间为索引 值,我的数据框架 temps 看起来是这样的.所以,总结起来,我有一个pandas数据框,以日期为datatimeindexes,以floats(温度)为列.我想把这个数据框的rekords按monts的测量值排序。

                 column      column
Index        | land_temps | ocean_temps
1861-01-01   |     -5     |    15
1861-02-01   |      0     |    17
1861-03-01   |      6     |    18
                   .
                   .
                   .
2015-11-01   |      2     |    17
2015-12-01   |     -1     |    14

所以,总的来说,我有一个pandas数据框,日期为datatimeindexes,浮点(温度)为列,我想把这个数据框中的rekords按测量的monts排序,实现这样的效果。

Index        | land_temps | ocean_temps
1861-01-01   |     -5     |    15
1862-02-01   |     -4     |    13
1863-03-01   |     -6     |    14
                   .
                   .
                   .
2014-12-01   |     -2     |    13
2015-12-01   |     -1     |    14

如何做到这一点?我已经试过了。

temps.sort_values(by=temps.index.month, axis='index')

but it does not work like that I guess, so is there any way to do thay using build in sortinggroupby panadas methods (or similar).

先谢谢你:)。)

python pandas dataframe sorting linear-regression
1个回答
© www.soinside.com 2019 - 2024. All rights reserved.