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]
2 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]2 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
Consider the following code:
lilavasa [31]

Answer:

integer

Explanation:

3 0
3 years ago
Read 2 more answers
Since cable tv and cable ​internet can share the same coaxial cable, they are considered to be what type of technology?
jekas [21]

broadband technology

6 0
3 years ago
Some problems are better solved by a computer and some are better solved by humans.
aalyn [17]

Answer:

I say when u don't know the answer completly.

3 0
2 years ago
An employee sets up an automation that transfers files in a specific folder on their PC to a remote drive for archiving, provide
Yuri [45]

Answer:

Rule based automation

Explanation:

8 0
2 years ago
In what tab can a user find the workspace option?
Sidana [21]
D. View.
You can find the workspace and preview of the file in View.
4 0
2 years ago
Other questions:
  • When employees are hired, they agree to only use cell phones during breaks. How would you classify this?
    8·2 answers
  • A disadvantage of ethernet??
    6·1 answer
  • Sam has installed a new CPU in a client’s computer, but nothing happens when he pushes the power button on the case. The LED on
    14·1 answer
  • What process combines data from a list with the content of a document to provide personalized documents?
    9·2 answers
  • Which of the following statements about renting and owning
    6·1 answer
  • What animal is perry the platypus ​
    6·2 answers
  • A student registers for a course in a university. Courses may have limited enrollment i.e a student must
    5·1 answer
  • Which organization publishes a handbook that describes various occupations? U.S. Department of Defense U.S. Department of Agricu
    15·1 answer
  • Logan has developed an excellent presentation with interesting content. He received great feedback on the evaluation
    10·1 answer
  • Which option on the Format tab is used to modify particular portions of the chart?
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!