如何删除 Pandas 数据帧索引的“秒”?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/28664430/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-13 22:58:39 来源:igfitidea点击:
How to remove the 'seconds' of Pandas dataframe index?
提问by hernanavella
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
谢谢
回答by JAB
you can use mapand strftimelike this:
你可以使用map并strftime喜欢这个:
df.index =df.index.map(lambda t: t.strftime('%Y-%m-%d %H:%M'))

