Skip to content
Advertisement

How to convert Array to pandas dataframe with datetime ohlcv efficiently, also divide column values by 100?

Following is the json output I am getting from api

JavaScript

I want to convert this json/array to timestamp, ohlcv data which has DateTime index and the ohlc values must be divided by 100 or sometime by 10000 depending upon the ticksize.

The final output must look something like below:

JavaScript

I know the answer is available on SO but I want to do it efficiently with less code and faster execution. Moreover, current data is 5min in case I get 1 min data, I would like to create a function to resample the data accordingly.
I will try to update the question with my current code soon.

Code for division by 100. I want to do this for 4 columns (o,h,l,c). Looking for a one liner.

JavaScript

Update:: Query is can this be done in an efficient way?
My current code::

JavaScript

Output ::

JavaScript

Advertisement

Answer

If you want to run it all together, I think you can also use the following method. Is this the best way to answer your question?

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