close
0

AttributeError: Can only use .dt accessor with datetimelike values

avatar
asked 23-06-2022

3 Answers


0

Try

df['Date'] = pd.to_datetime(df['Date'], errors='coerce')
avatar
answered 23-06-2022

0

Use 

import pandas as pd
file = '/pathtocsv.csv'
df = pd.read_csv(file, sep = ',', parse_dates= [col],encoding='utf-8-sig', usecols= ['Date', 'ids'],)    
df['Month'] = df['Date'].dt.month
avatar
answered 23-06-2022

0

Try

df_Time_Table["Date"] = pd.to_datetime(df_Time_Table["Date"])

# Cal Year
df_Time_Table['Year'] = df_Time_Table['Date'].dt.strftime('%Y')
avatar
answered 23-06-2022