Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Pulling data from API that disappears when added to pandas data frame?

So I have connected to bybits API and pulled some data that I’m trying to add to a pandas data frame. The original data is fine until I use the pandas data frame, this leads to some values missing. I’m new to coding and have tried solving / searching this problem myself but have had no luck. Any help is very much appreciated.


This is the output of the original data pulled from the API:

{‘ret_code’: 0, ‘ret_msg’: ‘OK’, ‘ext_code’: ”, ‘ext_info’: ”, ‘result’: [{‘id’: 28175809, ‘symbol’: ‘ETHUSDT’, ‘period’: ‘D’, ‘interval’: ‘D’, ‘start_at’: 1641168000, ‘open_time’: 1641168000, ‘volume’: 87839.49, ‘open’: 3826.2, ‘high’: 3861.9, ‘low’: 3681.35, ‘close’: 3761.95, ‘turnover’: 332049170.8095}], ‘time_now’: ‘1652781721.802819’}

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel


This is the output with the added data frame:

ret_code ret_msg ext_code ext_info
0 0 OK
0 {‘id’: 28175809, ‘symbol’: ‘ETHUSDT’, ‘period’… 1652781995.652047


As you can see there are many values missing when using the data frame

Here is my code:

import pandas as pd
from pybit import usdt_perpetual


session = usdt_perpetual.HTTP(
    endpoint='https://api.bybit.com', 
    api_key='',
    api_secret=''
)


data = (session.query_kline(
    symbol= "ETHUSDT",
    interval= "D",
    limit= 1,
    from_time= 1641085261
))


df = pd.DataFrame(data)

print(df)

>Solution :

df=pd.DataFrame(data).join(pd.DataFrame.from_dict(data['result'])).drop('result',axis=1)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading