'Convert df column to date

I have the following sample data to convert to date.

data = {'Dates':['20030430', '20010131', '20190805', '20191115']}
df = pd.DataFrame(data)

The code I am using is

df['Converted Date'] = pd.to_datetime(df['Dates'], format='%Y%m%d')

it gives the following error.

ValueError: time data '2011-10-13 00:00:00' does not match format '%Y%m%d' (match)

I tried

df['Converted Date'] = pd.to_datetime(df['Dates'], format='%Y%m%d%f')

which results in below error.

ValueError: time data '20190805' does not match format '%Y%m%d%f' (match)

Kindly help to resolve.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source