Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a function sort_records (csv f1lename, new f1lename) that sorts the records of a CSV file and writes the results as a new CSV file.

image text in transcribed

Write a function sort_records (csv f1lename, new f1lename) that sorts the records of a CSV file and writes the results as a new CSV file. The first column of the CSV file will be the city name. The rest of the columns will be months of the year. The first row of the CSV file will take the form of the column headings. Here is an example file fragment: x temp.csv c1ty/month,Jan, Feb,Mar,Apr Melbourne,41.2,35.5,37.4,29.3 Br1sbane,31.3,40.2,37.9,29 Darwin, 34,34,33.2,34.5 Note that your code will be tested over different CSV files, with different ranges of months in them. Irrespective of the exact months contained in the file, you may assume that the city name will always be in the first column, and the months in the remaining columns. You must sort the data in alphabetical order according to the city name (stored in the first column). Your program should write the sorted records to a new file with the name given by the argument new f1lename Here is an example of how sort_records should work: sort_records('max_temp.csv', 'sorted.csv) result open(' sorted. csv ' ) print (result.read)) result.close ) c1ty/month,Jan, Feb, Mar,Apr Br1sbane, 31.3,40.2,37.9,29 Darwin,34,34,33.2,34.5 Melbourne,41.2,35.5,37.4,29.3 Note that the row for Melbourne has been sorted below the rows for Brisbane and Darwin because Melbourne comes later than Br1sbane and Darwin, based on alphabetical ordering

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

Semantics In Databases Second International Workshop Dagstuhl Castle Germany January 2001 Revised Papers Lncs 2582

Authors: Leopoldo Bertossi ,Gyula O.H. Katona ,Klaus-Dieter Schewe ,Bernhard Thalheim

2003rd Edition

3540009574, 978-3540009573

More Books

Students also viewed these Databases questions