preprocessing.curate_data.reset_index(df, index_name='DateTime', timezone='UTC')
Resets the index of the dataframe and assigns a name to the index column.
Parameters
| df |
pd.DataFrame |
The input dataframe with a datetime index. |
required |
| index_name |
str |
The name to assign to the index column after resetting. Default is “DateTime”. |
'DateTime' |
| timezone |
str |
The timezone to localize the index to if it is naive. Default is “UTC”. |
'UTC' |
Returns
|
pd.DataFrame |
pd.DataFrame: The dataframe with the reset index. |
Examples
import pandas as pd
from spotforecast2_safe.preprocessing.curate_data import reset_index
date_rng = pd.date_range(start='2023-01-01', end='2023-01-02', freq='h')
data = pd.DataFrame(date_rng, columns=['date'])
data.set_index('date', inplace=True)
data['value'] = range(len(data))
reset_data = reset_index(data, index_name='DateTime')
print(reset_data.head())
DateTime value
0 2023-01-01 00:00:00+00:00 0
1 2023-01-01 01:00:00+00:00 1
2 2023-01-01 02:00:00+00:00 2
3 2023-01-01 03:00:00+00:00 3
4 2023-01-01 04:00:00+00:00 4