0

I have a column of Date in a Dataframe where the dates are written in this format -

No.  Date
0    25-Aug-47
1    16-Sep-48
2    03-Oct-49

I want to convert the values of Date Column into this format -

No.  Date
0    1947-08-25
1    1948-09-16
2    1949-10-03

first, I tried to do this -

df['Date'].apply(pd.to_datetime)

but this statement gives me this answer -

No.  Date
0    2047-08-25
1    2048-09-16
2    2049-10-03

then again I tried this -

def mdy_to_ymd(d):
    return datetime.strptime(d, '%d-%b-%y').strftime('%y-%m-%d')

for i in df['Date']:
    mdy_to_ymd(i)

this statement gives me this answer -

No.  Date
0    47-08-25
1    48-09-16
2    49-10-03
petezurich
  • 9,280
  • 9
  • 43
  • 57
JATIN
  • 170
  • 1
  • 7

0 Answers0