1

Is it possible to convert a series of dates in a column into a numeric index using pd.to_datetime? After that put it into a variable so I can print the value in a single variable.

default_date = ''
print(f'value of default_date' : {default_date}')

This is the data output enter image description here

For example: 2021-07-01 to 0 2021-07-02 to 1

Brody_Brody
  • 185
  • 16

1 Answers1

1

IIUC use:

df['date'] = pd.to_datetiem(df['date'])
df = df.set_index('date')

Or:

df = df.set_index('date')
df.index = pd.to_datetiem(df.index)
jezrael
  • 822,522
  • 95
  • 1,334
  • 1,252