Changing Pandas data-frame to JSON type

0 votes

I have this pandas data.frame with me:

print(abc)
    cyl  mpg
0    4  21.0
1    6  21.0
2    4  22.8
3    4  21.4
4    8  18.7
5    4  18.1

I would want to convert this pandas data-frame to a JSON format, like this:

{"cyl":4,"mpg":21.0}
{"cyl":6,"mpg":21.0}
{"cyl":4,"mpg":22.8}

May 22, 2018 in Data Analytics by DataKing99
• 8,100 points
48 views

1 answer to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
0 votes
abc.to_json(orient='records')

This command will give you the desired result:

[{"cyl":4,"mpg":21.0},{"cyl":6,"mpg":21.0},{"cyl":4,"mpg":22.8},{"cyl":4,"mpg":21.4},{"cyl":8,"mpg":18.7},{"cyl":4,"mpg":18.1}]
answered May 22, 2018 by anonymous

Related Questions In Data Analytics

0 votes
1 answer

Converting R data-frame to h2o object

All you have to do is run ...READ MORE

answered Apr 2, 2018 in Data Analytics by Bharani
• 4,550 points
386 views
0 votes
1 answer
0 votes
1 answer

How to convert a list of vectors with various length into a Data.Frame?

We can easily use this command as.data.frame(lapply(d1, "length< ...READ MORE

answered Apr 4, 2018 in Data Analytics by DeepCoder786
• 1,700 points
31 views
0 votes
2 answers

In data frame how to spilt strings into values?

You can do this using dplyr and ...READ MORE

answered Dec 4, 2018 in Data Analytics by Kalgi
• 35,750 points
22 views
0 votes
1 answer

Converting a pandas data-frame to a dictionary

Emp_dict=Employee.to_dict('records') You can directly use the 'to_dict()' function ...READ MORE

answered May 23, 2018 in Data Analytics by Bharani
• 4,550 points
710 views
0 votes
1 answer

Python equivalent to replace function in R

There is actually a replace function in ...READ MORE

answered May 30, 2018 in Data Analytics by Bharani
• 4,550 points
50 views
0 votes
1 answer

how can i count the items in a list?

suppose you have a list a = [0,1,2,3,4,5,6,7,8,9,10] now ...READ MORE

answered May 2 in Python by Mohammad
• 1,400 points
20 views
0 votes
1 answer

Applying the same function to every row of a data.frame - R

You can use the 'appply()' function for ...READ MORE

answered May 22, 2018 in Data Analytics by Bharani
• 4,550 points
24 views
0 votes
2 answers

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.