1

I tried to create a df from the following entries:

get_commission = {'info': {'symbol': 'ETHBTC', 'makerCommission': '0.001', 'takerCommission': '0.001'}, 'symbol': 'ETH/BTC:BTC', 'maker': 0.001, 'taker': 0.001} 
commission = pd.DataFrame(get_commission)

and the output is:

                   info       symbol marker  taker
makerCommission   0.001  ETH/BTC:BTC    NaN  0.001
symbol           ETHBTC  ETH/BTC:BTC    NaN  0.001
takerCommission   0.001  ETH/BTC:BTC    NaN  0.001

How can I get the df like:

symbol marker taker
ETH/BTC:BT 0.001 0.001

Thank you

RomanPerekhrest
  • 88,541
  • 4
  • 65
  • 105
Andy Bun
  • 25
  • 3
  • seems you just need to pass the nested dict `pd.DataFrame([get_commision['info']])`. There is no real pattern here. Pandas dataframe can get data as list of dicts (a.k.a. records), each one has keys as columns names and values as record values. – mr_mo Aug 21 '23 at 13:36
  • or alternatively pass the dict without the `'info'` key. This could help: https://stackoverflow.com/questions/31433989/return-copy-of-dictionary-excluding-specified-keys – Jeanot Zubler Aug 21 '23 at 13:37
  • Please remove the tag of `ccxt` as it is irrelevant to the question asked. Also, can you specify, do you want to create a whole new `df` or get the desired output from the `commission` created above? – Sam Aug 21 '23 at 13:40

2 Answers2

1

To get the expected result you need to exclude 'info' key from the input dict:

d = {k:v for k, v in get_commission.items() if k != 'info'}
commission = pd.DataFrame([d.values()], columns=d.keys())

        symbol  maker  taker
0  ETH/BTC:BTC  0.001  0.001
RomanPerekhrest
  • 88,541
  • 4
  • 65
  • 105
0

Alternative method. If you have multiple dictionary like info, include them in drop list.

df = pd.DataFrame([get_commission])
df.drop('info', axis = 1, inplace = True)

symbol  maker  taker
0  ETH/BTC:BTC  0.001  0.001
ragas
  • 848
  • 2
  • 7