Created
July 7, 2017 08:39
-
-
Save Kcrong/7525fe7e22ad1293ac74ced9a452b8d6 to your computer and use it in GitHub Desktop.
Excel to dict
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
import pandas as pd | |
from collections import defaultdict | |
multi_depth_defaultdict = lambda: defaultdict(multi_depth_defaultdict) | |
df = pd.read_excel('category.xlsx') | |
data = multi_depth_defaultdict() | |
for idx, df_data in df.iterrows(): | |
d1, d2, d3, d4 = [_.strip() for _ in df_data] | |
data[d1][d2][d3] = d4 | |
with open('category_dump.json', 'w') as f: | |
json.dump(data, f) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment