I have a JSON file that I took the keys from to use as rows for my data frame, next I took all the values from all the keys and put them into a flattened list. I want to use that list of values as the columns. However there's eight values and 5 keys
JSON:
{
"student1": [
"view_grades",
"view_classes"
],
"student2": [
"view_grades",
"view_classes"
],
"teacher": [
"view_grades",
"change_grades",
"add_grades",
"delete_grades",
"view_classes"
],
"principle": [
"view_grades",
"view_classes",
"change_classes",
"add_classes",
"delete_classes"
]
}
convert.py
def json_to_csv():
with open('C:/Users/Elitebook/Documents/GitHub/permissions.json') as json_file:
#convert to python dict
py_dict = json.load(json_file)
#first get a list of all the values(permissions) from the dict, flatten the list and return only unique values
permissions = sorted(set([key for value in py_dict.itervalues() for key in value]))
#create a dataframe from the python dictionary
pd.DataFrame.from_dict(py_dict, orient='index', columns=permissions)
I'm getting the AssertionError: 8 columns passed, passed data had 5 columns
error, I want to have it so I can have the 8 columns and 5 rows. Then I can put what I want in the value fields for the dataframe