2

I have a large data set contain a set of numbers

The data is fetched from server

Each row of data is like this:

{"body_data":[
{'height': 170.00, 'weight': 165.00, 'blood': 3.00, 'sugar': 100.02, 'fat': 36.02, 'time_object': 1544443260000},
{'height': 170.00, 'weight': 165.00, 'blood': 3.00, 'sugar': 100.02, 'fat': 36.02, 'time_object': 1544443260000},
],"symbol":"DATA_FAT","empty":false}

I tried to save the data into *.json format the import it as new file and rewrite it with csv yet I got error.

I tried with pandas the following code:

df = pd.DataFrame.from_dict(data, orient='index',columns=['open', 'height', 'weight', 'blood', 'sugar', 'fat', 'time_object'])

it gave me the following error:

 File "pandas/_libs/src/inference.pyx", line 1517, in pandas._libs.lib.to_object_array
TypeError: object of type 'bool' has no len()

can anyone help me please

2
  • 1
    please share your code. Commented Dec 28, 2018 at 6:49
  • Please paste the full error message, too Commented Dec 28, 2018 at 6:50

1 Answer 1

2

I believe you need select nested key body_data:

df = pd.DataFrame(data['body_data'])
print (df)
   blood    fat  height   sugar    time_object  weight
0    3.0  36.02   170.0  100.02  1544443260000   165.0
1    3.0  36.02   170.0  100.02  1544443260000   165.0

If want change ordering of columns (open key is not in sample data, so NaNs in output):

df = pd.DataFrame(data['body_data'],
                  columns=['open', 'height', 'weight', 'blood', 'sugar', 'fat', 'time_object'])
print (df)
   open  height  weight  blood   sugar    fat    time_object
0   NaN   170.0   165.0    3.0  100.02  36.02  1544443260000
1   NaN   170.0   165.0    3.0  100.02  36.02  1544443260000
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you very much problem solved, yes you are right i selected the body_data and now it works well.

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.