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,250 points
1,884 views

1 answer to this question.

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 3, 2018 in Data Analytics by Bharani
• 4,660 points
2,564 views
0 votes
1 answer
+1 vote
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,720 points
1,661 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 5, 2018 in Data Analytics by Kalgi
• 52,350 points
1,099 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,660 points
4,577 views
0 votes
1 answer

Python equivalent to replace function in R

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

answered May 31, 2018 in Data Analytics by Bharani
• 4,660 points
1,390 views
0 votes
2 answers
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 7, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 4,434 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,660 points
1,695 views
0 votes
2 answers

Replacing a row in pandas data.frame

key error. I love python READ MORE

answered Feb 18, 2019 in Data Analytics by anonymous
13,743 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP