I have an excel spreadsheet with some datetime data in a column. I exported the data into a dataframe using pandas. This column however has chunks of dates that have the month and day swapped, while there are other chunks of dates in the same column that are correct. Here's an example -
Figure 1: Day and month have been swapped incorrectly
The above picture shows the day and month swapped. The date shows 2016-01-10 but should instead be 2016-10-01. Compare this with another chunk of datetime values in the same column -
Figure 2: Day and month are correctly represented
In the above case in Figure 2, the month correctly represented as 12 and the day is 31.
I used the solution from this question - How to swap months and days in a datetime object?
I also tried using this solution - Python Pandas - Day and Month mix up
I also tried writing my own function to map to the entries but this was to no avail either -
def dm_swap(day, month):
if(month != 10 or month != 11 or month != 12):
temp = day
day = month
month = temp
t2016Q4.start.map(dmswap, t2016Q4.dt.day, t2016Q4.dt.month)
However, both solutions change all the datetime values in the column. So, when the incorrect values get corrected, the correct values become incorrect.
I've also linked the excel file for your convenience. It's an open data set.
Please choose the last dataset Bikeshare Ridership (2016 Q4). The "start" and "end" columns have the above mentioned issues.
Is there a more efficient way to clean the datetime data?

