How to create dummy column with “`yyyy-mm-dd“` format in Pandas?

Is it possible to create a dummy column with the yyyy-mm-dd format in pandas? I want to change the index column to the 2000-01-01 format and auto-fills the rest. Thanks.

enter image description here

Answer

You can set the index column to a pd.date_range() using the start and periods params:

df['index'] = pd.date_range(start='2000-01-01', periods=len(df))

#           index  raw
# 0    2000-01-01  169
# 1    2000-01-02  146
# 2    2000-01-03  161
# 3    2000-01-04  115
# 4    2000-01-05  185
# ...         ...  ...
# 1409 2003-11-10  177
# 1410 2003-11-11  156
# 1411 2003-11-12  144
# 1412 2003-11-13  101
# 1413 2003-11-14  109