如何删除 pandas 数据框索引的“秒"? [英] How to remove the 'seconds' of Pandas dataframe index?

查看:49
本文介绍了如何删除 pandas 数据框索引的“秒"?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

给出一个具有如下时间序列的数据框:

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

谢谢

推荐答案

您可以像这样使用mapstrftime:

df.index =df.index.map(lambda t: t.strftime('%Y-%m-%d %H:%M'))

这篇关于如何删除 pandas 数据框索引的“秒"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆