I have a data frame with dates and missing dates:
date
2022-02-02
2022-02-03
-
-
I need to convert to date only the ones different from '-', I'm using .loc for this but is not working:
df.loc[oppty['date'] != '-', 'date'] = pd.to_datetime(df['date'])
in parse raise ParserError("String does not contain a date: %s", timestr) dateutil.parser._parser.ParserError: String does not contain a date: -
CodePudding user response:
Will this work?
df1 = pd.DataFrame({'date':['2022-02-02', '2022-02-03', '-','-']})
df1
pd.to_datetime(df1['date'], errors='coerce')
if you want to keep '-'
change 'coerce'
to 'ignore'