I am reading data from a csv file, and I have a Date column formatted as "dd/mm/yyyy".
I just want to extract the month from it.
The problem is that in some cases (based on my observation it is when dd > 12), it returns the month correctly. Otherwise, it returns the day instead.
I tried extracting the day assuming that maybe the built-in format is "mm/dd/yyyy", but the same problem occurs. Only the year gets extracted correctly.
I have tried reformatting the date by replacing "/" with "-" but it did not solve the issue.
This is the code for extracting the month:
pd.DatetimeIndex(df['Date']).month
Here is an example of the results I'm obtaining.
Date: 19-01-2012,
Month: 01
Date: 04-01-2012,
Month: 04