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
Mation about which osi layers of connected cisco devices can be verified with the show cdp neighbors comm
fgiga [73]
The show CDP neighbor command operates at the Data link layer (Layer 2)

Cisco Discovery Protocol (CDP) is a proprietary Data Link Layer protocol developed by Cisco Systems. It is used to share information about other directly connected Cisco equipment, such as the operating system version and IP address.

6 0
3 years ago
True or False. A Windows Server 2016 that was installed in Desktop Experience mode can be converted to Server Core mode.
9966 [12]

When we install the Windows Server 2016 in Desktop Experience mode we cannot change it to Server Core mode. To change it we must uninstall it and reinstall it changing the mode (False).

<h3>What is Windows Server?</h3>

Windows Server is the name of a line of products created and marketed by the Microsoft Corporation software company.

One of its products is Windows Server 2016, this server was characterized by having two modes that were:

  • Desktop Experience
  • Server Core

However, it had the difficulty that the user could not switch between the two modes but had to uninstall and install the mode he wanted to use.

Learn more about Windows Server in: brainly.com/question/9426216

8 0
2 years ago
Into which of these files would you paste copied information to create an integrated document? A. Mailing list B. Source C. Data
viva [34]

it would be b.mailing list


5 0
3 years ago
Read 2 more answers
The term ________________ denotes data that is being stored on devices like a universal serial bus (USB) thumb drive, laptop, se
Vinvika [58]

Answer:

The term "Local storage"denotes data that is being stored on devices like a universal serial bus (USB) thumb drive, laptop, server, DVD, CD, or server. The term "hosted storage," "Internet storage" or "cloud storage." denotes data that exists in a mobile state on the network, such as data on the Internet, wireless networks, or a private network

4 0
3 years ago
Read 2 more answers
What is the space complexity of the algorithm?ArithmeticSeries(list, listSize) { i = 0 arithmeticSum = 0 while (i &lt; listSize)
blondinia [14]

Answer:

O(n) which is a linear space complexity

Explanation:

Space complexity is the amount of memory space needed for a program code to be executed and return results. Space complexity depends on the input space and the auxiliary space used by the algorithm.

The list or array is an integer array of 'n' items, with the memory size 4*n, which is the memory size of an integer multiplied by the number of items in the list. The listSize,  i, and arithmeticSum are all integers, the memory space is 4(3) = 12. The return statement passes the content of the arithmetic variable to another variable of space 4.

The total space complexity of the algorithm is "4n + 16" which is a linear space complexity.

7 0
2 years ago
Other questions:
  • Which character must decide whether to support the assassins or avenge his friend's death?
    14·2 answers
  • Why is a class called a factory of objects
    11·1 answer
  • 1. A tachometer measures:
    8·1 answer
  • In the URL, what is the subdomain and what is the domain name?
    5·1 answer
  • Why might an algorithm created to assist in hiring decisions be biased?
    15·1 answer
  • Read the following scenario what type of business letter do you think is required in this situation?
    12·2 answers
  • Take two String inputs of the same length and merge these by taking one character from each String (starting with the first ente
    8·2 answers
  • What is data science?​
    15·1 answer
  • The output of a computer can be seen on ( monitor, keyboard or mouse )​
    5·2 answers
  • A user generates printouts consisting of several pages of seemingly random characters every time he prints to a network printer.
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!