Showing a minimalist example below, I essentially have two functions, one to create a year column using "Date" column as input, and the other function which loads the data into a df from a csv file.
def create_year_column(df: pd.DataFrame) -> pd.DataFrame: df['year'] = df['date'].dt.year.astype(str) return dfdef load_data(path: str) -> pd.DataFrame: # load the data from csv file data = pd.read_csv( path, dtype={'amount': float,'category': str,'date': str, }, parse_dates=['date'] ) create_year_column(data) return dataThe problem I have is that when I run this in python 3.10 I get the following error:
AttributeError: Can only use .dt accessor with datetimelike values. Did you mean: 'at'?
It seems to have issues with the line of code where I use:
df['year'] = df['date'].dt.year.astype(str)I technically assume that the df['date'] column is allready parsed as a date format, which it is since its called in the load_data() function after I format it as such (using: parse_dates=['date'] ).
When I run this code in pyton 3.9 I have no issues, only 3.10 is giving me heartache. Anyone know why?