Skip to content
Advertisement

Setting Time with interval of 1 minute

I have a dataset which comprises of minutely data for 2 stocks over 3 months. I have to create date in the first column and time (with interval of 1 minute) in the next column for 3 months. I am attaching the snap of 1 such data set. Kindly help me to solve this problem.

Data Format

Advertisement

Answer

-Create 3 month range numpy array of dates and time with minute frequency

JavaScript

-Isolate dates

JavaScript

-Isolate times

JavaScript

-Create pandas dataframe with 2 columns (date and time)

JavaScript

-Then simply concat the new dataframe with your existing dataframe on the column axis.

***** Remove Saturday and Sunday *****

You could remove weekends by creating a column with weekend day names and then taking a slice of the dataframe exluding Saturday and Sunday:

JavaScript

Remove Sat and Sun with this code:

JavaScript

As for Holidays, you could use the same method but you would need a list of the holidays applicable in your region.

****** Trading times ******

JavaScript

******* Exclude specific day ******

JavaScript

Lastly, don’t forget to reset your dataframe’s index.

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement