Answered step by step
Verified Expert Solution
Question
1 Approved Answer
For this project, you will import the json module. Write a class named SatData that reads a JSON file containing data on 2 0 1
For this project, you will import the json module.
Write a class named SatData that reads a JSON file containing data on SAT results for New York City and writes the data to a text file in CSV format. That same JSON file will be provided as a local file in Gradescope named sat.json, so you don't need to upload it to Gradescope. Your code does not need to access the internet. For testing on your computer, download the file at that link and put it in your PyCharm project.
CSV is a very simple format just commas separating columns and newlines separating rows see note below about commas that are part of field names You'll see an example of CSV format below. There is a csv module for Python, but you will not use it for this project.
Your class should have:
an init method that reads the file and stores it in whatever data members you prefer. Any data members of the SatData class must be private.
a method named saveascsv that takes as a parameter a list of DBNs district bureau numbers and saves a CSV file that looks like this, but with only the rows that correspond to the DBNs in the list and also the row of column headers To see what CSV syntax looks like, open the file as a text file rather than as a spreadsheet. You may assume that all of the DBNs in the list passed to your method are present in the JSON file. The rows in the CSV file must be sorted in ascending order by DBN The name of the output file must be output.csv
For example, your class could be used like this:
sd SatData
dbns MMMM
sdsaveascsvdbns
You may hardcode the column headers instead of having to read them from the JSON file.
Some of the school names contain one or more commas. How should you preserve such a name as a single field in CSV format, since commas normally separate fields? The correct way to handle that is to enclose such names in double quotes in your CSV file. If you open up the example CSV file in a text editor, you can see that's what it does.
Don't let the CSV part intimidate you. You're just taking the values for a row, making them into a string that has commas between the values and with double quotes around the values that contain commas and then writing those strings to a file.
The file must be named: SatData.py
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started