I am trying to clean and convert some columns in a dataframe from dtype 'object' to dtype 'datetime':
column_names = ['col a','col b', ...'col n']
df[column_names] = df[column_names].apply(pd.to_datetime, format = '%m/%Y')
But this seems to take a very long time - and right now I am only cleaning a subset of a much larger file.
Is there a quicker way to achieve this?
I note that this file opened via pd.read_csv, and even with 'parse_dates' set to True, the relevant columns are read as 'object.'