I have a DataFrame read from Excel with one of the columns of type DateTime.
sales_data=pandas.read_excel(r'Sample Sales Data.xlsx')
I was able to extract substrings from other columns using str.extract/lambda functions. But I was unable to process the column "Order Date"
The command sales_data['Order Date']
gives the below output
As recommended in other StackOverflow questions, I tried with
sales_data['Order Date'].apply(lambda x:x.str.slice())
I got an error that : AttributeError: 'datetime.datetime' object has no attribute 'str' To check the type of the Order date column, I tried
sales_data['Order Date'].apply(lambda x:type(x))
I got the type datetime.datetime
But when I tried the datetime operation
sales_data['Order Date'].apply(lambda x:x.strftime("m"))
I got the error: AttributeError: 'int' object has no attribute 'strftime' I got a similar error for the command
sales_data['Order Date'].apply(lambda x:x.dt.month)
Please suggest a method to extract month from the datetime object into another column without iterating through the DataFrame. I am not able to use datetime or int functions with this column since it is behaving as both a datetime and int column.