I am doing data preprocessing, so I am trying to convert the date string format into an int, but I got an error, please help me how to convert it.
I have data like this :
0 Apr-12
1 Apr-12
2 Mar-12
3 Apr-12
4 Apr-12
I tried this :
d=df['d_date'].apply(lambda x: datetime.strptime(x, '%m%Y'))
I got an error.
ValueError Traceback (most recent call last)
<ipython-input-134-173081812744> in <module>()
----> 1 d=test['first_payment_date'].apply(lambda x: datetime.strptime(x, '%m%Y'))
~\Anaconda3\lib\site-packages\pandas\core\series.py in apply(self, func, convert_dtype, args, **kwds)
4036 else:
4037 values = self.astype(object).values
-> 4038 mapped = lib.map_infer(values, f, convert=convert_dtype)
4039
4040 if len(mapped) and isinstance(mapped[0], Series):
pandas\_libs\lib.pyx in pandas._libs.lib.map_infer()
<ipython-input-134-173081812744> in <lambda>(x)
----> 1 d=test['first_payment_date'].apply(lambda x: datetime.strptime(x, '%m%Y'))
~\Anaconda3\lib\_strptime.py in _strptime_datetime(cls, data_string, format)
563 """Return a class cls instance based on the input string and the
564 format string."""
--> 565 tt, fraction = _strptime(data_string, format)
566 tzname, gmtoff = tt[-2:]
567 args = tt[:6] + (fraction,)
~\Anaconda3\lib\_strptime.py in _strptime(data_string, format)
360 if not found:
361 raise ValueError("time data %r does not match format %r" %
--> 362 (data_string, format))
363 if len(data_string) != found.end():
364 raise ValueError("unconverted data remains: %s" %
ValueError: time data 'Apr12' does not match format '%m%Y'
%b-%y. See this for more info.pd.to_datetime(df['d_date'],format='%b-%y')expanding on what @harvpan saysmachine-learning- kindly do not spam irrelevant tags (removed & replaced withdatetime).