Question: Write as a Python beginner. Print output as show for each step for the file below. This is the M 2 . csv file: name

Write as a Python beginner. Print output as show for each step for the file below.
This is the M2.csv file:
name id nametype mass (g) fall year reclat reclong
Aachen 1 Valid 21 Fell 188050.7756.08333
Aarhus 2 Valid 720 Fell 195156.1833310.23333
Abee 6 Valid 107000 Fell 195254.21667-113
Acapulco 10 Valid 1914 Fell 197616.88333-99.9
Achiras 370 Valid 780 Fell 1902-33.1667-64.95
1. Read the attached CSV file one line at a time (equivalent to one row at a time).(skip the first line/row containing the columns names i.e.)
2. Store the row as a dictionary (Python)
3. Store the output of Step 2 into a list/array.
4. Convert the output of Step 3 into JSON .
5. Write the output of Step 4 into a JSON file. Name of output file shoud be output.json
6. Take the output of Step 5 and convert it into a CSV file. The content will be identical to what was used as input in Step 1.
Lets say I have a CSV file with the following content: (this is just example, please make sure the output will look like this and the code should work for the M2.csv file above)
ID,Name,Age
1,"John Smith",23
2,"Matt Johnson",32
3,"Cindy Colins",30
First read this file one line/row at a time (skip the first line/row containing the columns names i.e.)
Line 1-1,"John Smith",23
Line 2-2,"Matt Johnson",32
Line 3-3,"Cindy Colins",30
Step 2: Convert the lines into a dictionary/map (print the dictionaries, they should look like the following)
{'ID': '1', 'Name': '"John Smith"', 'Age': '23'}
{'ID': '2', 'Name': '"Matt Johnson"', 'Age': '32'}
{'ID': '3', 'Name': '"Cindy Colins"', 'Age': '30'}
Step 3: Store the dictionaries from Step 2 into a list/array.(print the output of this step it should look like the following)
[{'ID': '1', 'Name': '"John Smith"', 'Age': '23'},{'ID': '2', 'Name': '"Matt Johnson"', 'Age': '32'},{'ID': '3', 'Name': '"Cindy Colins"', 'Age': '30'}]
Step 4: Use the output of Step 3 and conver it into JSON object. Print the output, should look like the following.
[{"ID": "1", "Name": "\"John Smith\"", "Age": "23"},{"ID": "2", "Name": "\"Matt Johnson\"", "Age": "32"},{"ID": "3", "Name": "\"Cindy Colins\"", "Age": "30"}]
Step 5: Store the output of Step 4 into a file output.json The contents of the file is identical to output of Step 4.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!