1

I can parse the following data. but I cannot show it as a table in columnar. How can I chart this?

 for item in items:
     print(item['symbol'])
[
{"symbol": "ZILUSDT", "positionAmt": "0", "entryPrice": "0.00000", "markPrice": "0.01728152", "unRealizedProfit": "0.00000000", "liquidationPrice": "0", "leverage": "20", "maxNotionalValue": "25000", "marginType": "cross", "isolatedMargin": "0.00000000", "isAutoAddMargin": "false", "positionSide": "SHORT"}, 
{"symbol": "FLMUSDT", "positionAmt": "0", "entryPrice": "0.0000", "markPrice": "0.00000000", "unRealizedProfit": "0.00000000", "liquidationPrice": "0", "leverage": "20", "maxNotionalValue": "25000", "marginType": "cross", "isolatedMargin": "0.00000000", "isAutoAddMargin": "false", "positionSide": "BOTH"}, 
{"symbol": "FLMUSDT", "positionAmt": "0", "entryPrice": "0.0000", "markPrice": "0.00000000", "unRealizedProfit": "0.00000000", "liquidationPrice": "0", "leverage": "20", "maxNotionalValue": "25000", "marginType": "cross", "isolatedMargin": "0.00000000", "isAutoAddMargin": "false", "positionSide": "LONG"}, 
{"symbol": "FLMUSDT", "positionAmt": "0", "entryPrice": "0.0000", "markPrice": "0.00000000", "unRealizedProfit": "0.00000000", "liquidationPrice": "0", "leverage": "20", "maxNotionalValue": "25000", "marginType": "cross", "isolatedMargin": "0.00000000", "isAutoAddMargin": "false", "positionSide": "SHORT"}
]



How can I show it in a table like the one below?

     headers = ["Symbol", "EntryPrice", "side", "position"]
     symbols = [x['symbol'] for x in data]
     table = columnar(symbols, headers=headers)
     print(table)
2
  • What do you mean by "chart"? Do you mean you want to create an actual image (i.e. JPEG or GIF)? Commented Oct 30, 2020 at 16:32
  • pypi.org/project/Columnar no man i want to create like here Commented Oct 30, 2020 at 16:35

2 Answers 2

2

You have a list of dictionaries. The easiest way is to wrap them into pandas' DataFrame, which handles that type out-of-the box.

import pandas as pd

tabulated = pd.DataFrame(items)
print(tabulated)
Sign up to request clarification or add additional context in comments.

1 Comment

for sym in items: tabulated = pd.DataFrame(sym['symbol'], sym['entryPrice']) print(tabulated)
0

Pandas is an excellent solution, but you can natively present data in table format too:

for row in zip(*([key] + (value) for key, value in sorted(items.items()))):
    print(*row)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.