Home > front end >  How to splits the long numeric into date format?
How to splits the long numeric into date format?

Time:06-29

[![enter image description here][1]][1][![enter image description here][2]][2]

  • I have data frames of 10*75 format.
  • Each cell in 3rd column only contains 0123456789 and I want to splits in date format like 0123 as days, 45 as hours, 67 minutes and 89 seconds respectively. How to split or access numerical values at different positions?

[1]: https://i.stack.imgur.com/CP5BG.jpg I have such format of column [2]: https://i.stack.imgur.com/yagPb.jpg I need to make like date format as shown in the output picture.

CodePudding user response:

You can subset strings like this: string[start:end:step]

so it would be:

number = "0123456789"
day= number[0:4]
hour= number[4:6]
minute = number[6:8]
second= number[8:]

edit:

sorry dident se you used a dataframe, then the syntax is this:

df['day'] = df['col'].str[0:4]
df['hour'] = df['col'].str[4:6]
df['minute'] = df['col'].str[6:8]
df['second'] = df['col'].str[8:]
  • Related