PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Friday, October 7, 2022

[FIXED] how can I find a date with incorrect Syntax and fix it

 October 07, 2022     pandas, python, statistics     No comments   

Issue

I am new to python. I have a dataset I converted it to dataframe. all my dates are objects now. I need to convert them into dates in order to find the age of patients. My dimensions are 3400x14 long. there are date values inside which have incorrect syntax. I cannot find them. is there a way to find them?

Cdf['Birthday'] = Cdf['Birthday'].astype('datetime64[ns]')

I am using this formula to convert. I need date without time. I am getting an error which is "DateParseError: Invalid date specified (25/15)"

Thank you for help in advance


Solution

You can use pd.to_datetime

Cdf['date'] = pd.to_datetime(Cdf['Birthday'], errors='coerce')

and check for which values in this column have NaTs as values. All invalid dates will be converted to NaT. You can use

Cdf.loc[Cdf['date'].isnull(), 'date']

to find all values which are invalid.



Answered By - rafaelc
Answer Checked By - Willingham (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing