Issue
i currently have a dataset
date_checkout_y
18000809 5
18001017 6
18001226 8
18001229 8
18010216 10
i want to split date_checkout_y to create a datetime
tried
df['date_checkout_y'] = df.date_checkout_y.str.split(n=1,expand=True)
but getting an error
Solution
use from apply method (if your col is string else convert it to string)
from datetime import datetime
def f(x):
return datetime(year=x[:4], month=x[4:6], day=x[6:8]
df['new'] = df['date_checkout_y'].apply(f)
Answered By - Alireza
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.