I am importing a json file into a python3 jupyter notebook. The json file has the format
- object
- rooms [26 elements]
- 0
- turns
- fromBathroom
- fromParking
- distances
- dfromBathroom
- dfromParking
- depth
- area
- turns
- 1
- .... etc.
- 0
- name
- rooms [26 elements]
I am importing the json file in this way:
import pandas as pd
import numpy as np
import json
from pandas.io.json import json_normalize
with open("rooms.json") as file:
data = json.load(file)
df = json_normalize(data['rooms'])
I am now trying to plot each of the 6 dimensions against each other in a matrix-like format, with 36 total graphs.
I am trying to this the following way:
col_features = ['fromBathroom', 'fromParking', 'dfromBathroom', 'dfromParking', 'depth', 'area']
pd.plotting.scatter_matrix(df[col_features], alpha = .2, figsize = (14,8))
This does not work, as I am getting an error that reads: KeyError: "['fromBathroom' 'fromParking' 'dfromBathroom' 'dfromParking'] not in index"
This is because those features are nested in 'turns' and 'distances' in the json file. Is there a way to un-nest these features so that I can index into the dataframe the same way I can for depth and area to get the values?
Thank you for any insights.