- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Write a Python code to read JSON data from a file and convert it to dataframe, CSV files
Assume you have the following sample json data stored in a file as pandas_sample.json
{ "employee": { "name": "emp1", "salary": 50000, "age": 31 } }
The result for after converting to csv as,
,employee age,31 name,emp1 salary,50000
Solution
To solve this, we will follow the steps given below −
Create pandas_sample.json file and store the JSON data.
Read json data from the file and store it as data.
data = pd.read_json('pandas_sample.json')
Convert the data into dataframe
df = pd.DataFrame(data)
Apple df.to_csv function to convert the data as csv file format,
df.to_csv('pandas_json.csv')
Example
Let’s see the below implementation to get a better understanding −
import pandas as pd data = pd.read_json('pandas_sample.json') df = pd.DataFrame(data) df.to_csv('pandas_json.csv')
Output
employee age 31 name emp1 salary 50000
- Related Articles
- Python - How to write pandas dataframe to a CSV file
- How to put a Pandas DataFrame into a JSON file and read it again?
- Write a Python code to combine two given series and convert it to a dataframe
- How to create a file, write data into it and read data from it on iOS?
- Write data from/to a .csv file in java
- How to read the data from a CSV file in Java?
- Write a program in Python to read CSV data from a file and print the total sum of last two rows
- How to read a JSON file into a DataFrame using Python Pandas library?
- How to read data from *.CSV file using JavaScript?
- How to read data from .csv file in Java?
- How to convert JSON file to CSV file using PowerShell?
- Write a C program to read a data from file and display
- How to convert JSON to CSV file using PowerShell?
- Python Pandas- Create multiple CSV files from existing CSV file
- How to read CSV file in Python?

Advertisements