Python implementation read JSON file to Excel table

Source: Internet
Author: User
This article mainly introduces the Python implementation to read the JSON file to Excel table, with a certain reference value, interested in small partners can refer to

The example of this article for everyone to share the Python implementation to read the JSON file to Excel table for your reference, the specific content is as follows

First, the demand

1, ' Score.json ' file contents:

{  "1": ["Floret", 99,100,98.5],  "2": ["Xiao Wang", 90,30.5,95],  "3": ["Xiao Ming", 67.5,49.6,88]}

2, read the JSON file to save to the database, and calculate the total score and the average of each person

Second, the implementation of the Code

Import JSON, Xlwtdef Read_score (jsonfile): With  open (jsonfile, encoding= ' Utf-8 ') as F: # Convert the JSON file to a dictionary    score_all = Json.load (f) Book  = XLWT. Workbook () # Create Excel file  sheet = book.add_sheet (' Sheet1 ') # Create a table  title = [' Serial number ', ' name ', ' language ', ' math ', ' English ', ' total score ', ' average ' ] for  col in range (len title): # Deposit First Row header    sheet.write (0, col, Title[col]) Row  = 1 # define row for  K in Score_all :    data = score_all[k] # data holds names and fractions of list    data.append (sum (data[1:4)) # The penultimate column adds total    data.append (sum (data[ 1:4])/3.0) # The last column adds an average of    Data.insert (0, K) # The first column is added to the ordinal for    index in range (len data): # Write each line      Sheet.write (r OW, index, Data[index])    row + = 1  book.save (' Score.xls ') read_score (' Score.json ')

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.