Home > OS >  How to covnert int64 data into ?day, month and year?
How to covnert int64 data into ?day, month and year?

Time:07-11

I have a date feature in the format 20001130 and another 2000-11-30 without any space. How can i write the optimized code that works for both to split the date into day month and year efficiently

CodePudding user response:

You can use pandas.to_datetime:

import pandas as pd
pd.to_datetime([20001130, 20001129], format='%Y%m%d')

or with a dataframe.

df = pd.DataFrame({'time': [20001129, 20001130]})
df.time = pd.to_datetime(df.time, format='%Y%m%d')
time
0 2000-11-29
1 2000-11-30
  • Related