How to convert CSV file to JSON file using Pandas

0 votes

Hi Guys,

I have one CSV file. I want to convert this file into JSON format. How can I do this?

Jun 25, 2020 in Python by akhtar
• 38,260 points
11,381 views

1 answer to this question.

0 votes

Hi@akhtar,

You can convert your CSV file to JSON format using Pandas. In Pandas, you can find the to_json function. It will help you to do your task. I have attached one example for your reference.

import pandas as pd
data = pd.read_csv('my.csv')
Place,State
Kolkata,WestBengal
Delhi,Delhi
Bangalore,Karnataka
Kolkata,WestBengal
Delhi,Delhi
data.to_json(path_or_buf='my.json',orient='records',lines=True)
{"Place":"Kolkata","State":"WestBengal"}
{"Place":"Delhi","State":"Delhi"}
{"Place":"Bangalore","State":"Karnataka"}
{"Place":"Kolkata","State":"WestBengal"}
{"Place":"Delhi","State":"Delhi"}

I hope this will help you.

answered Jun 25, 2020 by MD
• 95,460 points

Related Questions In Python

+1 vote
1 answer

how to convert json to csv or to store in sql

You can convert JSON data to csv ...READ MORE

answered Jul 2, 2018 in Python by Nietzsche's daemon
• 4,260 points
2,296 views
0 votes
1 answer

How can I convert JSON to CSV?

I am not sure this question is ...READ MORE

answered Oct 1, 2018 in Python by aryya
• 7,460 points
11,585 views
+1 vote
5 answers

How to read Pandas csv file with no header?

Use this logic, if header is present ...READ MORE

answered Mar 14, 2020 in Python by Shahabuddin
• 160 points
230,423 views
0 votes
1 answer

How to create blank csv file in pandas?

Try this code: open("User data.csv", 'w') Where User data.csv ...READ MORE

answered Apr 6, 2019 in Python by Will
4,469 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
+5 votes
6 answers

Lowercase in Python

You can simply the built-in function in ...READ MORE

answered Apr 11, 2018 in Python by hemant
• 5,790 points
4,067 views
0 votes
1 answer

How to ignore Headers in S3 bucket CSV file using python?

Hi@durgaraju, You can fetch only the body part. ...READ MORE

answered Dec 29, 2020 in Python by MD
• 95,460 points
2,187 views
0 votes
1 answer

How to convert sqlite format to CSV format?

Hi@akhtar, If you want to read SQLite format ...READ MORE

answered Feb 11, 2020 in Python by MD
• 95,460 points
2,967 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