Reputation: 125
I have a dataset that looks like this:
And I want to have a column that's called "Date" and has all the dates that I currently have as rows. Does anyone have any idea how to do that?
Upvotes: 1
Views: 61
Reputation: 1179
Your dataframe has the dates as an index, so reset index to pull them out into a column. If the index was previously named something other than 'index', use that name instead of 'index' if you choose to rename it.
df = pd.DataFrame([[2], [4]], columns=['order'])
df = df.reset_index()
df = df.rename(columns={'index':'date'})
print(df)
# date order
# 0 0 2
# 1 1 4
Upvotes: 1