How to remove the 'seconds' of Pandas data

2019-06-20 04:54发布

Given a dataframe with time series that looks like this:

                      Close
2015-02-20 14:00:00  1200.1
2015-02-20 14:10:00  1199.8
2015-02-21 14:00:00  1199.3
2015-02-21 14:10:00  1199.0
2015-02-22 14:00:00  1198.4
2015-02-22 14:10:00  1199.7

How can I get rid of the 'seconds' of the index so it looks like this:

                   Close
2015-02-20 14:00  1200.1
2015-02-20 14:10  1199.8
2015-02-21 14:00  1199.3
2015-02-21 14:10  1199.0
2015-02-22 14:00  1198.4
2015-02-22 14:10  1199.7

Thanks

1条回答
神经病院院长
2楼-- · 2019-06-20 05:11

you can use map and strftime like this:

df.index =df.index.map(lambda t: t.strftime('%Y-%m-%d %H:%M'))
查看更多
登录 后发表回答