I have a program that spits out
{'candles': [{'open': 1260.25, 'high': 1260.5, 'low': 1260.0, 'close': 1260.28,
'volume': 2544, 'datetime': 1556029980000}, {'open': 1260.39, 'high': 1260.61,
'low': 1260.3501, 'close': 1260.3501, 'volume': 1703, 'datetime':
1556030040000}, {'open': 1260.35, 'high': 1260.59, 'low': 1260.07, 'close':
1260.56, 'volume': 2156, 'datetime': 1556030100000}, {'open': 1260.56, 'high':
1260.56, 'low': 1259.27, 'close': 1259.7, 'volume': 1320, 'datetime':
1556030160000}, {'open': 1260.06, 'high': 1260.06, 'low': 1259.56, 'close':
1259.56, 'volume': 800, 'datetime': 1556030220000},
I need to insert that into a pandas df with Open High Low Close and volume being each column.
How would I do that with having to manually input it?
If your dictionary just has 1 key with all of the records in it, you can just do:
data = {'candles': [
{'close': 1260.28, 'datetime': 1556029980000, 'high': 1260.5, 'low': 1260.0, 'open': 1260.25, 'volume': 2544},
{'close': 1260.3501, 'datetime': 1556030040000, 'high': 1260.61, 'low': 1260.3501, 'open': 1260.39, 'volume': 1703},
{'close': 1260.56, 'datetime': 1556030100000, 'high': 1260.59, 'low': 1260.07, 'open': 1260.35, 'volume': 2156},
{'close': 1259.7, 'datetime': 1556030160000, 'high': 1260.56, 'low': 1259.27, 'open': 1260.56, 'volume': 1320},
{'close': 1259.56, 'datetime': 1556030220000, 'high': 1260.06, 'low': 1259.56, 'open': 1260.06, 'volume': 800}]}
df = pd.DataFrame(data["candles"])
print(df)
open high low close volume datetime
0 1260.25 1260.50 1260.0000 1260.2800 2544 1556029980000
1 1260.39 1260.61 1260.3501 1260.3501 1703 1556030040000
2 1260.35 1260.59 1260.0700 1260.5600 2156 1556030100000
3 1260.56 1260.56 1259.2700 1259.7000 1320 1556030160000
4 1260.06 1260.06 1259.5600 1259.5600 800 1556030220000
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.