I'm trying to create a YYYY-MM-DD HH:MM:SS AM/PM format (for e.g. 2017-01-01 12:00:00 AM) from a. A date column that is of the DDMMMYYYY format (for e.g. 01JAN2017); and b. A time column that is of the HH:MM:SS AM/PM (for e.g. 12:00:00 AM) format.
The AM/PM in (b) appears to be the biggest problem.
I've tried a few approaches from stack overflow a. read.csv(parse_dates = [['date','time]]), and then re-arranging the date-time column using pd.to_datetime(df, format='%d%b%Y %H:%M:%S'). b. Converting 'date' using the datetime function and 'time' function to timedeltas using pd.time_delta before trying to concatenate both of them. c. Looping(Combine date and time columns using datetime) d. Writing a parser, and then including the parser into the pd.read_csv command together with parse_dates = [['date','time']]. (Convert string date time to pandas datetime)
a. df = pd.read_csv('a.csv',parse_dates=[['date','time']])
df['datetime'] = pd.to_datetime(df['datetime'], format = format='%d%b%Y %H:%M:%S)
b. df = pd.read_csv('a.csv')
df["Date"] = pd.to_datetime(df["Date"])
df["Time"] = pd.to_timedelta(df["Time"])
df["DateTime"] = df["Date"] + df["Time"]
c. Same as the code in the link
d. Same as the code in the link
I received plenty of error messages on formats because the time column has the AM or PM portion after the HH:MM:SS portion.