Reputation: 741
I am quite new to Python but trying to do some machine learning with it.
My problem is to format a received JSON object into an array like structure to submit this to my predictor function of the ML model.
JSON object looks like when I do a print of it
{u'CRIM': 0.62739, u'ZN': 0, u'B': 395.62, u'LSTAT': 8.47, u'AGE': 56.5, u'TAX': 307, u'RAD': 4, u'CHAS': 0, u'NOX': 0.538, u'MEDV': 19.9, u'RM': 5.834, u'INDUS': 8.14, u'PTRATIO': 21, u'DIS': 4.4986}
what i need is
[0.62739, 0, 395.62, 8.47, 56.5, 307, 4, 0, 0.538, 19.9, 5.834, 8.14, 21, 4.4986]
Can anybody help here thanks Peter
Upvotes: 0
Views: 39
Reputation: 3140
What you are looking for is
d = {'a':1, 'b': 2, 'c': 3}
num_list = d.values()
# num_list = [1,2,3]
Upvotes: 0
Reputation: 5194
try:
json_var = {u'CRIM': 0.62739, u'ZN': 0, u'B': 395.62, u'LSTAT': 8.47, u'AGE': 56.5, u'TAX': 307, u'RAD': 4, u'CHAS': 0, u'NOX': 0.538, u'MEDV': 19.9, u'RM': 5.834, u'INDUS': 8.14, u'PTRATIO': 21, u'DIS': 4.4986}
value_array = json_var.values()
Upvotes: 1