Unable to convert JSON file to CSV using Python

Tsing

I was trying to convert the below JSON file into a csv file.

JSON file

[{
"SubmitID":1, "Worksheet":3, "UserID":65,
 "Q1":"395",
 "Q2":"2178",
 "Q3":"2699",
 "Q4":"1494"},{
 "SubmitID":2, "Worksheet":3, "UserID":65,
  "Q4":"1394"},{
 "SubmitID":3, "Worksheet":4, "UserID":65,
  "Q1":"1629",
  "Q2":"1950",
  "Q3":"0117",
  "Q4":"1816",
 "Empty":" "}]

However, my Python code below gives the error message "TypeError: Expected String or Unicode". May I know how should I modify my program to make it work?

import json
import pandas as pd

f2 = open('temp.json')
useful_input = json.load(f2)
df=pd.read_json(useful_input)
print(df)
df.to_csv('results.csv')
Akavall

You just need to pass the address string to pd.read_json():

df=pd.read_json("temp.json")

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Unable to convert JSON file to CSV using Python

From Dev

Convert JSON to CSV when file has different keys using Python?

From Dev

How to convert a large Json file into a csv using python

From Dev

Convert JSON file to a CSV file using R

From Dev

convert whole csv to json file- python

From Dev

how to convert csv file to json using jquery and download that json file

From Dev

Convert CSV to JSON (in specific format) using Python

From Dev

Convert CSV to JSON (in specific format) using Python

From Dev

directly convert CSV file to JSON file using the Jackson library

From Dev

How to convert STL file in JSON using Python

From Dev

Python convert JSON to CSV

From Dev

How do I convert a .csv file to .db file using python?

From Dev

How to convert a CSV file into a JSON script using Node.js?

From Dev

How to convert csv file to json using C++

From Dev

Unable to Save Arabic Decoded Unicode to CSV File Using Python

From Dev

Convert CSV to JSON and JSON to CSV using PowerShell

From Dev

How can I convert a XLSB file to csv using python?

From Dev

How do I convert a csv file to xlsb using Python?

From Dev

unable to convert tab delimited .txt file to csv

From Dev

How to convert specific CSV format to JSON using Python

From Dev

Convert csv to JSON using JavaScriptSerializer

From Dev

Convert CSV to JSON using PHP

From Dev

Convert JSON to CSV using Pandas

From Dev

Convert a JSON into CSV using jq

From Dev

convert csv to json using jackson

From Dev

Convert XML to csv file with Python

From Dev

Convert csv file into python dictionary

From Dev

How to convert csv to json in python?

From Dev

JSON to CSV in python convert issue

Related Related

HotTag

Archive