I'm a pandas learner.
I have a dataframe with the column 'DATE', the datetime format of the column is like '11/1/2017 1:00'. I want to change the datetime format from '11/1/2017 1:00' to '1-Dec-17 1:00', I tried the following code:
dir_path = os.path.dirname(os.path.realpath("__file__"))
print(dir_path)
def parse_dates(x):
return datetime.strptime(x, "%d-%b-%y %H:%M")
df = pd.read_csv(dir_path+"/TEST.csv", parse_dates=['DATE'],date_parser=parse_dates)
But it shows error:
ValueError: time data '11/1/2017 1:00' does not match format '%d-%b-%y %H:%M'
I also tried to convert the dataframe, but failed:
df=pd.read_csv(dir_path+"/TEST.csv")
df['DATE'] = pd.to_datetime(df['DATE'],format='%d-%b-%y %H:%M')
Again, it shows error:
ValueError: time data '11/1/2017 1:00' does not match format '%d-%b-%y %H:%M' (match)