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
63 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 2, 2018 in Data Analytics by Bharani
• 4,550 points
453 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
45 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
• 37,320 points
36 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
960 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
57 views
+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 6 in Python by Neha
• 330 points

edited Jul 8 by Kalgi 122 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
31 views
0 votes
2 answers