0

I would like to parse the year column to datetime.

    name    id  nametype    recclass    mass (g)    fall    year                    
0   Aachen  1   Valid       L5         21.0         Fell    01/01/1880 12:00:00 AM

... reclat      reclong     GeoLocation
... 50.77500    6.08333    (50.775000, 6.083330)

df['year'].apply(dateutil.parser.parse) and that parses as 1880-01-01 00:00:00 but i can use that for selecting dates. Do anyone have a tip for me?

2 Answers 2

2

I think need to_datetime:

df = pd.DataFrame({'year':['01/01/1880 12:00:00 AM']})

df['year'] = pd.to_datetime(df['year'])
print (df)
        year
0 1880-01-01
Sign up to request clarification or add additional context in comments.

Comments

0

Since you have converted the year column to datetime, you can use:

df['year'] = df['year'].dt.date
# year    
# 1880-01-01

However, for datetime casting, note that pandas has an inbuilt datetime parser that is easy to use than dateutil IMO.

2 Comments

Thanks but this didnt work. Can only use .dt accessor with datetimelike values
You mentioned that you did df['year'].apply(dateutil.parser.parse) which makes the year column a datetime column. This assumes that it is the case.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.