我已将以下字符串转换为json:
data = {"MessageCode":1502,
"MessageVersion":4,
"ApplicationType":0,
"TokenID":0,
"ExchangeSegment":1,
"ExchangeInstrumentID":22,
"ExchangeTimeStamp":1309954231,
"Bids":[{"Size":21,"Price":1999.15,"TotalOrders":2,"BuyBackMarketMaker":0},
{"Size":20,"Price":1999.1,"TotalOrders":1,"BuyBackMarketMaker":0},
{"Size":40,"Price":1999.05,"TotalOrders":1,"BuyBackMarketMaker":0},
{"Size":185,"Price":1999,"TotalOrders":6,"BuyBackMarketMaker":0},
{"Size":7,"Price":1998.8,"TotalOrders":2,"BuyBackMarketMaker":0}],
"Asks":[{"Size":1,"Price":1999.8,"TotalOrders":1,"BuyBackMarketMaker":0},
{"Size":3,"Price":1999.85,"TotalOrders":1,"BuyBackMarketMaker":0},
{"Size":34,"Price":1999.9,"TotalOrders":2,"BuyBackMarketMaker":0},
{"Size":199,"Price":2000,"TotalOrders":10,"BuyBackMarketMaker":0},
{"Size":1,"Price":2000.05,"TotalOrders":1,"BuyBackMarketMaker":0}],
"Touchline":{"BidInfo":{"Size":21,"Price":1999.15,"TotalOrders":2,"BuyBackMarketMaker":0},
"AskInfo":{"Size":1,"Price":1999.8,"TotalOrders":1,"BuyBackMarketMaker":0},
"LastTradedPrice":1999.9,
"LastTradedQunatity":12,
"TotalBuyQuantity":145954,
"TotalSellQuantity":81287,
"TotalTradedQuantity":114118,
"AverageTradedPrice":1999.65,
"LastTradedTime":1309954224,
"LastUpdateTime":1309954231,
"PercentChange":0.6365580576173091,
"Open":1997.65,
"High":2006.6,
"Low":1989.1,
"Close":1987.25,
"TotalValueTraded":null,
"BuyBackTotalBuy":0,
"BuyBackTotalSell":0},
"BookType":1,
"XMarketType":1,
"SequenceNumber":476310325663841}
我想将数据[“投标”][0][0](即大小:21)转换为一列,然后将数据[“投标”][0][1]转换为另一列,将数据[“投标”][0][2]转换为第三列。。。。。。。同样,我想要37个这样的专栏,即:
1: Date (now.day)
2. Time (convert ExchangeTimeStamp to current time)
3. ExchangeInstrumentID
4-33. [bid_size1, bid_price1, bid_totalorder1, bid_size2, bid_price2, bid_totalorder2, ....bid_size5, bid_price5, bid_totalorder5, ask_size1, ask_price1, ask_totalorder1, ...ask_size5, ask_price5, ask_totalorder5]
34. LastTradedPrice
35. LastTradedQunatity
36. LastTradedTime (converted to present timestamp)
37. LastUpdateTime (converted to present timestamp)
这就是我尝试过的:
rename = {'TotalOrders':'_totalorder'}
df = pd.concat([pd.DataFrame(d['Bids']).rename(columns=rename).add_prefix('bid'),
pd.DataFrame(d['Asks']).rename(columns=rename).add_prefix('ask')], axis=1)
这给了我6列,而不是6*5=30列。请帮忙
1条答案
按热度按时间fnvucqvd1#
尝试:
印刷品: