Рассмотрим следующий фрейм данных:
import pandas as pd
import datetime
raw_data = {'Player': ['Matthew', 'John', 'Lisa', 'Taylor',
'Matthew', 'John', 'Lisa', 'Taylor',
'Matthew', 'John', 'Lisa', 'Taylor',
'Matthew', 'John', 'Lisa', 'Taylor'],
'Race Number': [1, 1, 1, 1,
2, 2, 2, 2,
3, 3, 3, 3,
4, 4, 4, 4],
'Place': [2, 1, 3, 4,
3, 2, 4, 1,
1, 3, 4, 2,
2, 1, 3, 4],
'Date of Race': ['1/1/2019','1/1/2019','1/1/2019','1/1/2019',
'1/2/2019','1/2/2019','1/2/2019','1/2/2019',
'1/3/2019','1/3/2019','1/3/2019','1/3/2019',
'1/4/2019','1/4/2019','1/4/2019','1/4/2019'
]}
mariokartdata = pd.DataFrame(raw_data)
mariokartdata.dtypes
Возвращает:
Player object
Race Number int64
Place int64
Date of Race object
Но если вы запустите:
mariokartdata['Date of Race'] = pd.to_datetime(mariokartdata['Date of Race'])
mariokartdata.dtypes
Теперь вернется:
Player object
Race Number int64
Place int64
Date of Race datetime64[ns]
Тем самым создается значение datetime для столбца ['Date of Race'].