Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In this assignment, you will read some data from a CSV file and perform some data processing and print the results in a text file.

In this assignment, you will read some data from a CSV file and perform some data processing and print the results in a text file. You will save your assignment code as ISM3115Assign6ByLastNameFirstName.py and submit it. Add a single line comment that says This is assignment 6 by Add a multi-line comment that says In this assignment I will learn how to read data from a CSC file, how to process that data and how to write the processed data in an output file Please break up the above comment into multiple lines (two or more). Open an output text file called OlympicVenuesByYear.txt Next, read a CSV file called SummerOlympicsData.csv provided with this assignment. This data file has eight fields City, Year, Sport, Discipline, Country, Gender and Medal. Read the eight fields one row at a time. After reading the first row, print the following sentence: The Summer Olympics were held in Use print formatting approach to print the above line. Print the same thing in the output file. The second row has the same City and Year as the first row, so do not do anything. Keep reading the rows till the year changes. When it changes, print the same thing as above on the computer and also in the output file. There is data on 26 Olympics. So your output text file should have data for 26 Olympic years and their Cities, like this: The 1896 Summer Olympics were held in Athens The 1900 Summer Olympics were held in Paris The 1904 Summer Olympics were held in St Louis The 1908 Summer Olympics were held in London The 1912 Summer Olympics were held in Stockholm The 1920 Summer Olympics were held in Antwerp The 1924 Summer Olympics were held in Paris The 1928 Summer Olympics were held in Amsterdam The 1932 Summer Olympics were held in Los Angeles The 1936 Summer Olympics were held in Berlin The 1948 Summer Olympics were held in London The 1952 Summer Olympics were held in Helsinki The 1956 Summer Olympics were held in Melbourne / Stockholm The 1960 Summer Olympics were held in Rome The 1964 Summer Olympics were held in Tokyo The 1968 Summer Olympics were held in Mexico The 1972 Summer Olympics were held in Munich The 1976 Summer Olympics were held in Montreal The 1980 Summer Olympics were held in Moscow The 1984 Summer Olympics were held in Los Angeles The 1988 Summer Olympics were held in Seoul The 1992 Summer Olympics were held in Barcelona The 1996 Summer Olympics were held in Atlanta The 2000 Summer Olympics were held in Sydney The 2004 Summer Olympics were held in Athens The 2008 Summer Olympics were held in Beijing

So far I have written this code to satisfy the requirements:

#This is Assignment 6 by Gregory Gauthier

''' In this Assignment I will learn how to read data from a CSC file, how to process that data, and how to write the processed data in an output file. '''

f = open('OlympicVenuesByYear.txt', 'w') Year = 0 import csv with open ('SummerOlympicsData.csv', 'r') as csvfile: csvreader = csv.reader(csvfile) for row in csvreader: colnum = 1 for col in row: if colnum == 1: City = col colnum = 2 elif colnum == 2: Year = col colnum = 3 elif colnum == 3: Sport = col colnum = 4 elif colnum == 4: Discipline = col colnum = 5 elif colnum == 5: Country = col colnum = 6 elif colnum == 6: Gender = col colnum = 7 else: Medal = col colnum = 1 f.write('The %d Summer Olympics were held in %s'%(Year, City)+ ' ') print('The {1:d} Summer Olympics were held in {0:s}'.format(City, Year))

f.close()

Would appreciate any help given.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Intelligent Databases Object Oriented Deductive Hypermedia Technologies

Authors: Kamran Parsaye, Mark Chignell, Setrag Khoshafian, Harry Wong

1st Edition

0471503452, 978-0471503453

More Books

Students also viewed these Databases questions