Вот так я и начал получать все данные в DataFrame. Я добавил новый столбец под названием «легенда», который позволит вам просматривать все данные отдельно при необходимости:
import pandas as pd
import requests
# needs header
headers = {'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) '\
'AppleWebKit/537.36 (KHTML, like Gecko) '\
'Chrome/75.0.3770.80 Safari/537.36'}
URI = 'https://www.nseindia.com/api/live-analysis-variations?index=gainers'
# since data is returned as json, we can use .json func
data = requests.get(URI, headers=headers).json()
print(data['legends'])
# each legend carries data, so we will append all data and add col legend
dfs = pd.DataFrame([])
for legend, _ in data['legends']:
df = pd.DataFrame(data[legend]['data'])
df['legend'] = legend
dfs = dfs.append(df, ignore_index=True)
print(dfs)