1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
LenaWriter [7]
3 years ago
10

Write a Python program that reads the CSV file, compares the population estimates of every row for 2010 and 2017 and computes th

e difference in populations as well as the percentage of change (in 2 decimal points).
Computers and Technology
1 answer:
Svetllana [295]3 years ago
3 0

Answer:

  1. import csv  
  2. with open('data.csv') as file:
  3.    records = csv.reader(file, delimiter = ",")
  4.    year = 2010
  5.    for row in records:
  6.        if (year == 2010):
  7.            print(str(year) + ": " + row[1])
  8.            previous_pop = int(row[1])
  9.            year = year + 1
  10.            print("\n")
  11.        else:
  12.            difference = abs(int(row[1]) - previous_pop)
  13.            percent = (difference / previous_pop) * 100
  14.            print(str(year) + ": " + row[1])
  15.            print("Difference: " + str(difference))
  16.            print("Percentage difference: " + str(round(percent,2)) + "%")
  17.            print("\n")
  18.            previous_pop = int(row[1])

Explanation:

Presume that there is a CSV file with 8 records. Each records have a year and population value.

Firstly, we can import the CSV module and use it to open and read the CSV file (Line 1 - 4)

Next we can use a for loop to traverse through the read data row by row (Line 6).

For the first row (year 2010), we can print out the year and population and assign the population to a variable previous_pop and increment the year by 1 (Line 9 -10).

When the year is more than 2010, we can start calculating the difference and percentage of difference of population (Line 13 -14). Then we can print out the details (Line 15 - 17) and repeat the same process in the next iteration.

You might be interested in
What do astronomers call a system that is composed of more than two stars?
Nezavi [6.7K]
Nazils system is the anwser
7 0
3 years ago
Read 2 more answers
The severity of a burn or shock is not dependent on
Mariulka [41]

Hi Brainiac


The severity of a burn or shock is not dependent on the location or the distance from source


I hope that's help:0

5 0
3 years ago
_____ is a scam in which access to one's own computer is locked or restricted in some way.
gtnhenbr [62]
Ransomware is the answer to this.
5 0
3 years ago
Which of the following statements correctly instantiate the Rectangle object myRectangle? (i) myRectangle Rectangle = new Rectan
madreJ [45]

Answer:

The answer is "option iii"  .

Explanation:

In the given question it is defined that a class "Rectangle" is defined in the class a parameter constructor is created that accepts two parameters. In this question, we create an instance of the class. In object creation first, we define class name then object name and use new keyword in the Instance of class and pass parameters.

  • In option i), An object name is used first and then class name. It is not correct.
  • In option ii), In instance creation of the class, we do not use class keyword that's why it is wrong.

5 0
4 years ago
Read 2 more answers
A scientist conducted an experiment and discovered that certain plants grow faster when given a particular amount of fertilizer.
belka [17]

the answer is B: Replication, i put validity on e2020 and it was wrong.

3 0
4 years ago
Read 2 more answers
Other questions:
  • You have connected thirteen pcs and laptops to a wireless network. to make your wlan more secure, what should you do to disallow
    11·1 answer
  • Video-sharing sites allow videos to be uploaded in which file format? A. .avi B. .svg C. .tiff D. .xls
    5·1 answer
  • What specific database stores local user accounts on local computers, and allows users to sign in to and access resources only o
    9·1 answer
  • ∑_(A,B,C,D,E)▒〖(2,4,6,8,10,12,14,16,18,20,22,24,26,28,30)〗
    8·1 answer
  • What is cutting-edge technology
    6·1 answer
  • Ram is also called __________________________________________________
    11·1 answer
  • Heeeeeeeeeeeeeeeeeeelp plz
    11·1 answer
  • What practice makes it virtually impossible to figure out the geographic location of a company?
    7·1 answer
  • What are the steps for rearranging the layout of a form?
    7·1 answer
  • Kevin, a manager at FitPlus fitness club, owns a website that updates information regarding his fitness club. He created backgro
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!