Reputation: 117
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
Upvotes: 0
Views: 1106
Reputation: 28565
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
Upvotes: 0
Reputation: 42678
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
Upvotes: 2