I originally have some time series data, which looks like this and have to do the following:
- First import it as dataframe
- Set date column as datetime index
- Add some indicators such as moving average etc, as new columns
- Do some rounding (values of the whole column)
- Shift a column one row up or down (just to manipulate the data)
- Then convert the df to list (because I need to loop it based on some conditions, it's a lot faster than looping a df because I need speed)
- But now I want to convert df to dict instead of list because I want to keep the column names, it's more convenient
But now I found out that convert to dict takes a lot longer than list. Even I do it manually instead of using python built-in method.
My question is, is there a better way to do it? Maybe not to import as dataframe in the first place? And still able to do Point 2 to Point 5? At the end I need to convert to dict which allows me to do the loop, keep the column names as keys? THanks.
P.S. the dict should look something like this, the format is similar to df, each row is basically the date with the corresponding data.