0

I've a nested dictionary in json format for which I want to create html tables to send in an email according to key :

converting it into html table is where I'm stuck

{"test.txt": {"apple": "554", "banana": "23"}, "example.txt": {"apple": "551", "bannan": "2"}}

Tables should be like : Basically key as header

------------ 
 test.txt
------------    

apple 554

banana 23

1
  • What have you already tried? Please read How to Ask Commented Apr 12, 2019 at 15:13

2 Answers 2

2

Just iterate throught your data structure:

>>> for n, values in data.items():
...     print(f"------------\n{n}\n------------")
...     for k, v in values.items():
...         print(k, v)
... 
------------
test.txt
------------
apple 554
banana 23
------------
example.txt
------------
apple 551
bannan 2
Sign up to request clarification or add additional context in comments.

Comments

0

You could do something like this:

import pandas as pd

data = {"test.txt": {"apple": "554", "banana": "23"}, "example.txt": {"apple": "551", "banana": "2"}}


df = pd.DataFrame.from_dict(data, orient='columns')

Output:

print (df)
       test.txt example.txt
apple       554         551
banana       23           2   

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.