In Python
Please use the same USPopulation.txt file from Project 8 as input data. For this project, read the data into a list of lists (a 2-dimensional list, 4 decades, each decade with 10 years). Compute the annual change in the population, and the year with the maximum and minimum population change. Using Anaconda, plot a graph for each decade's population change.
The attached file USPopulation.txt contains the US population in thousands, during the years 1950 through 1990. The first line in the file contains the population for 1950, the second line contains the population for 1951, and so forth.
USPopulation.txt
151868
153982
156393
158956
161884
165069
168088
171187
174149
177135
179979
182992
185771
188483
191141
193526
195576
197457
199399
201385
203984
206827
209284
211357
213342
215465
217563
219760
222095
224567
227225
229466
231664
233792
235825
237924
240133
242289
244499
246819
249623
#importing the numpy to reshape into desired shape
import numpy as np
#importing matplotlib to plot the graph
import matplotlib.pyplot as plt
sublist = list()
#decade x label
decades = ["1-2","2-3","3-4"]
#opening the file to read the data
with open("USPopulation.txt","r") as rd:
lines = rd.readlines()
for line in lines:
#stroing the values to list
sublist.append(int(line))
#converting into numpy array
sublist = np.array(sublist)
#reshaping the list to list of list
sublist = np.reshape(sublist,(4,10))
diff=0
#list to hold each decade differenece
difflist = list()
for i in range(1,sublist.shape[0]):
diff = sum(sublist[i]) - sum(sublist[i-1])
difflist.append(diff)
#variable to hold max difference
maxdiff = 0
#variable to hold min difference
mindiff = 100000
for i in sublist:
for j in range(1,len(i)):
diffYear = i[j]-i[j-1]
if(diffYear<mindiff):
mindiff =
diffYear
if(diffYear>maxdiff):
maxdiff =
diffYear
print("the maximum difference between population",maxdiff)
print("the minimum difference between population",mindiff)
#plotting the graph
plt.bar(decades, difflist, align='center', alpha=0.5)
plt.xlabel("difference of decades")
plt.ylabel('')
#show the graph
plt.show()
In Python Please use the same USPopulation.txt file from Project 8 as input data. For this project, read the data into a list of lists (a 2-dimensional list, 4 decades, each decade with 10 years). Com...
The attached file US Population.txt contains the US population in thousands, during the years 1950 through 1990. The first line in the file contains the population for 1950, the second line contains the population for 1951, and so forth. Write a program that reads the file's contents into a list. The program should display the following data: the average annual change in population during the time period. You will notice the population numbers are always increasing. So rather than finding...
C# Visual Studio Problem You are given a file named USPopulation.txt. The file contains the midyear population of the United States, in thousands, during the years 1950 through 1990. The first line in the file contains the population for 1950, the second line contains the population for 1951, and so forth. Create an application that reads the file’s contents into an array or a List. The application should display the following data (statistics) in read-only textboxes. The average population during...
the language is in Python please help Instructions from your teacher. Instructions The US Population.txt file contains the midyear population of United States, in thousands, during the years 1950 through 1990. The first line in the file contains the population for 1950, the second line contains the population for 1951, and so forth. Create an application that reads the file's contents into a list. The application should do the following: • (15 points) Read the file into an list of...
Coding for Python - The pattern detection problem – part 2: def calculate_similarity_list(data_series, pattern) Please do not use 'print' or 'input' statements. Context of the assignment is: In this assignment, your goal is to write a Python program to determine whether a given pattern appears in a data series, and if so, where it is located in the data series. Please see attachments below: We need to consider the following cases: Case 1 - It is possible that the given...