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'}
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)
CodePudding user response:
df=pd.DataFrame(data).join(pd.DataFrame.from_dict(data['result'])).drop('result',axis=1)