Skip to content
Advertisement

Manipulate the Dataframe to start from the nearest varying Midnight timestamp

My goal:

I have a dataset that gets generated every day at random hours leading to the first row to start at a random time. I want to make this dataset start from the nearest midnight date. For example, if the date on the first row is 2022-05-09 15:00:00, I would have to slice the data to make it start from the nearest midnight, in this case: 2022-05-10 00:00:00

Here’s what the dataset looks like:

data

What I have tried:

I had the idea of locating the index of the first occurrence of my desired timestamp and applying iloc to create the desired data set.

JavaScript

results: [Timestamp(‘2022-05-10 00:00:00’)]

However, this would only result in extracting the timestamp where it first appears, and I would not be able to apply iloc to the row value. As of now, I’m stuck and can’t think of a more elegant solution, which I’m sure exists.

I would be grateful if you could recommend a better method to this. Thank you in advance!

Here’s the complete code to extract the df:

pip install ccxt

JavaScript

The dictionary format: (as suggested)

JavaScript

Advertisement

Answer

my minimalistic approach of the pandaNewstarter you simply can apply it to your candlestick_df:

JavaScript

out:

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