0

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

1
  • the problem with what you are trying to do is that the order of the key/values is not guaranteed by json specifications in an object. Commented Nov 12, 2015 at 21:38

2 Answers 2

1

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()
Sign up to request clarification or add additional context in comments.

1 Comment

@PeterHIRT your welcome, if my answer helped you, please accept it.
0

What you are looking for is

d = {'a':1, 'b': 2, 'c': 3}
num_list = d.values()

# num_list = [1,2,3]

1 Comment

When I was writing this, no other answer was there

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.