0

I am converting the date column to pandas date, date column have date with time, some are invalid entry for that I am ignoring that. Date column looks like this image with some nat value enter image description here

I am using below code

df['datePublished']=pd.to_datetime(df['datePublished'], errors="coerce")
df_1 = df[df['datePublished'] >= '2022-01-01']

Error message:

TypeError: '>=' not supported between instances of 'datetime.datetime' and 'str'

How to convert the different dates in a column into pandas date?

5
  • possible duplicate of this question Commented Sep 8, 2023 at 18:55
  • 1
    Does this answer your question? Converting between datetime and Pandas Timestamp objects Commented Sep 8, 2023 at 19:00
  • post the code and not the pictures of code. Users need to be able to replicate the problem quickly, which text allows for (and pictures do not). how to ask Commented Sep 8, 2023 at 19:32
  • Refrain from showing your dataframe as an image. Your question needs a minimal reproducible example consisting of sample input, expected output, actual output, and only the relevant code necessary to reproduce the problem. See How to make good reproducible pandas examples for best practices related to Pandas questions. Commented Sep 8, 2023 at 23:58
  • df_1=df[df['datePublished'].ge(pd.Timestamp('2022-01-01')]? Commented Sep 9, 2023 at 2:12

0

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.