In: Computer Science
Create a python script that reads in the contents of CityPop.csv and stores the data in a container. Task 2 will expect that your program can find cities by name within the container, so think about that as you set up your data container. Briefly describe how you store the data in comments. *It won't let me post the CSV file
fileName = 'CityPop.csv' container = dict() # ignore first line, as that is header lines = open(fileName).readlines()[1:] for line in lines: # capture the attributes you require attrs = line.split(',') city = attrs[3] id = int(attrs[0]) yr2010Population = float(attrs[13]) # i am capturing just 3 attributes for each record. # You can capture whatever you require. container[city] = {'city': city, 'id': id, 'yr2010Population': yr2010Population} # Now container contains data for all the cities.. # you can print the data for whatever city you want. print(container['Shanghai'])
************************************************** Here is how my .csv file looks like:Thanks for your question. We try our best to help you with detailed answers, But in any case, if you need any modification or have a query/issue with respect to above answer, Please ask that in the comment section. We will surely try to address your query ASAP and resolve the issue.
Please consider providing a thumbs up to this question if it helps you. by Doing that, You will help other students, who are facing similar issue.