Question: 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.

 Write a function sort_records (csv f1lename, new f1lename) that sorts the

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

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!