from string to timedelta in pandas

后端 未结 4 1427
遥遥无期
遥遥无期 2020-12-19 21:58

I have a dataframe where the timestamp is in the format HHHHH:MM

timestamp = pd.Series([\'34:23\',\'125:26\',\'15234:52\'], index=index)

I

4条回答
  •  孤城傲影
    2020-12-19 22:02

    You can use pandas.Series.apply, i.e.:

    def convert(args):
        return timedelta(hours=int(args[:-3]),minutes=int(args[-2:]))
    s = pd.Series(['34:23','125:26','15234:52'])
    s = s.apply(convert)
    

提交回复
热议问题