Pandas: checking invalid values in to_datetime function

jabba

im trying to convert string into datetype using:

df.apply(pd.to_datetime)

that throws: ('month must be in 1..12', 'occurred at index 'my_column')

Adding errors='coerce' fixes problem

df.apply(pd.to_datetime, errors='coerce')

But is there any way to check and display the invalid values?

It_is_Chris

You can just create a new column then use boolean indexing:

# sample data
df = pd.DataFrame({'str':['2019-01-01', '2019-02-01', '2019-13-01']})
# adding a new column that is datetime
df['date'] = pd.to_datetime(df['str'], errors='coerce')
# boolean indexing
df[df['date'].isna()]


        str     date
2   2019-13-01   NaT

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Is 'format' an invalid parameter to to_datetime in pandas?

Pandas : 'to_datetime' function not consistent with dates

Pandas to_datetime function giving erratic output

Using pandas to_datetime in custom function

specify the time zone for pandas to_datetime function

How to format datetime values in columns without to_datetime functions in pandas?

Pandas' to_datetime function doesn't change dtype

Apply pandas to_datetime function to excel date format

Convert month name to decimal using 'to_datetime' function in Pandas

pandas to_datetime formatting

Pandas to_datetime with multiindex

Pandas replace invalid datetime values with values from other columns

Pandas to_datetime loses timezone

Apply to_datetime with parameters in pandas

Pandas to_datetime inconsistent conversions

Using pandas to_datetime with timestamps

pandas to_datetime() not detecting columns

Pandas to_datetime ignore the format

Pandas "to_datetime" not accepting series

IBM DB2 CAST AS VARCHAR versus Python Pandas to_datetime Function

The function returns invalid values

Converting an object to datetime with Pandas to_datetime not working

Comparing pandas to_datetime with datetime object

Pandas to_datetime() issue with specific datetime format

pandas to_datetime() then concat() on DateTime Index

Checking IF a column's values in a pandas df are in a list

checking if values are existed or new using pandas

Pandas Dataframe Checking Consecutive Values in a colum

Exclude certain values when checking for a condition with pandas