Question

In: Computer Science

Write a program that reads and parses the CSV file, and can sort and filter data...

Write a program that reads and parses the CSV file, and can sort and filter data according to the user input and print the results.

Your program should be able to do the following according to the user input:

1. Show results from a specific country

2. Sort the data according to any column

3. Filter the results (for example, >10000 cases)

4. Print the top or bottom n results

You get bonus points if your program

• Can do partial country name search, meaning ”Tur” matches Turkey, ”Aus” matches Austria and Australia, etc.

• Saves the state of the CSV file (ordering) for later launches of the application.

• Visualizes the data in some way.

NOTE: While we cannot attach any file to a Chegg question, you can create an empty csv (Excel) file and paste the parameters below, into this file please. (There are more rows in the original file).

Country/Region,Confirmed,Deaths,Recovered,Active,New cases,New deaths,New recovered,Deaths / 100 Cases,Recovered / 100 Cases,Deaths / 100 Recovered,Confirmed last week,1 week change,1 week % increase,WHO Region
Afghanistan,32672,826,19164,12682,348,7,1833,2.53,58.66,4.31,30616,2056,6.72,Eastern Mediterranean

Albania,2819,74,1637,1108,67,2,45,2.63,58.07,4.52,2330,489,20.99,Europe

Cameroon,12592,313,10100,2179,0,0,0,2.49,80.21,3.1,12592,0,0.0,Africa

Canada,107172,8731,0,98441,223,10,0,8.15,0.0,Infinity,104865,2307,2.2,Americas

Turkey,204610,5206,179492,19912,1154,20,1214,2.54,87.72,2.9,195883,8727,4.46,Europe
US,2839436,129676,894325,1815435,45283,242,103921,4.57,31.5,14.5,2510259,329177,13.11,Americas
Uganda,927,0,868,59,16,0,19,0.0,93.64,0.0,848,79,9.32,Africa
Ukraine,48628,1243,21907,25478,923,16,611,2.56,45.05,5.67,42932,5696,13.27,Europe

Solutions

Expert Solution

import pandas as pd
if name == '__main__':
  
try:
dataset = pd.read_csv("dataset.csv")
while(True):
print("1.Show results from a specific country","2.Sort the data according to any column","3.Filter the results"
,"4.Print top n resuls","5.Print bottom n results","6.Save dataset","7.Exit",sep='\n')
choice = input()
if choice == '1':
print("Enter full/partial country name")
country = input()
print(dataset.loc[dataset["Country/Region"].str.contains(country)].stack(dropna=False))
elif choice == '2':
column_list = (dataset.columns.values)
for column_name in column_list:
print(column_name)
print("Select column name to sort")
column_name = input()
if column_name in column_list:
print("1.Ascending\n2.Descending")
sort_order = input()
if sort_order == '1':
dataset.sort_values(by=[column_name],inplace=True)
elif sort_order == '2':
dataset.sort_values(by=[column_name],inplace=False,ascending=False)

else:
print("Select valid column name")
elif choice == '3':
column_list = (dataset.columns.values)
for column_name in column_list:
print(column_name)
print("Select column name to filter")
filter_column = input()
if filter_column in column_list:
print("Enter value to filter")
filter_value = input()
if dataset[filter_column].dtypes == 'int64':
filter_value = int(filter_value)
elif dataset[filter_column].dtypes == 'float64':
filter_value = float(filter_value)

print('Filter options\n1.Greater than\n2.Greater than equal to\n3.Less than\n4.Less than equal to\n',
'5.Equal\n6.Not equal to')
filter_choice = input()
if filter_choice == '1':
print(dataset[dataset[filter_column] > filter_value])
elif filter_choice == '2':
print(dataset[dataset[filter_column] >= filter_value])
elif filter_choice == '3':
print(dataset[dataset[filter_column] < filter_value])
elif filter_choice == '4':
print(dataset[dataset[filter_column] <= filter_value])
elif filter_choice == '5':
print(dataset[dataset[filter_column] == filter_value])
elif filter_choice == '6':
print(dataset[dataset[filter_column] != filter_value])

else:
print("Enter valid choice")
else:
print('Enter valid column name')

elif choice == '4':
print("Enter number of rows")

try:
num = int(input())
print(dataset.head(num))
except:
print("Enter valid number")
elif choice == '5':
print("Enter number of rows")

try:
num = int(input())
print(dataset.tail(num))
except:
print("Enter valid number")
elif choice == '6':
print("Enter filename")
filename = input()
try:
dataset.to_csv(filename+".csv",index=False)
except:
print("Failed to save file")
elif choice == '7':
break
else:
print("Wrong choice")
except:
print("Failed to open CSV file")

*Change csv name as your file name*


Related Solutions

In this programming assignment, you will write a program that reads in the CSV file (passenger-data-short.csv),...
In this programming assignment, you will write a program that reads in the CSV file (passenger-data-short.csv), which contains passenger counts for February 2019 on 200 international flights. The data set (attached below) is a modified CSV file on all International flight departing from US Airports between January and June 2019 reported by the US Department of Transportation. You write a program that give some summary statistics on this data set. Create a header file named flights.h. In this file, you...
Write a program that reads in a continuous stream of strings representing a line of CSV...
Write a program that reads in a continuous stream of strings representing a line of CSV data in the format "NAME,AGE,EMAIL,DOB". Implement a function check_csv which verifies that each input string matches this format by ensuring that: • There are 4 tokens in the string corresponding to the 4 properties above. • The second token MUST be a number. • The fourth token should be in the format MM-DD-YYYY (hint: tokenize this as well). The function should return 0 if...
I am trying to create a program that reads from a csv file and finds the...
I am trying to create a program that reads from a csv file and finds the sum of total volume in liters of liquor sold from the csv file by county and print that list out by county in descending order. Currently my program runs and gives me the right answers but it is not in descending order. I tried this:     for county, volume in sorted(sums_by_volume.items(), key=lambda x: x[1], reverse=True):         index +=1         print("{}. {} {:.2f}".format(county, sums_by_volume[county]))      When I run...
Write a program in Java that reads a file containing data about the changing popularity of...
Write a program in Java that reads a file containing data about the changing popularity of various baby names over time and displays the data about a particular name. Each line of the file stores a name followed by integers representing the name’s popularity in each decade: 1900, 1910, 1920, and so on. The rankings range from 1 (most popular) to 1000 (least popular), or 0 for a name that was less popular than the 1000th name. A sample file...
Write a C++ or Java program that reads an input graph data from a user. Then,...
Write a C++ or Java program that reads an input graph data from a user. Then, it should present a path for the travelling salesman problem (TSP). In the assignment, you can assume that the maximum number ofvertices in the input graph is less than or equal to 20. Input format: This is a sample input from a user. 4 12 0 1 2 0 3 7 0 2 5 1 0 2 1 2 8 1 3 3 2...
Write a Java program that reads an input graph data from a user. Then, it should...
Write a Java program that reads an input graph data from a user. Then, it should present a path for the travelling salesman problem (TSP). In the assignment, you can assume that the maximum number of vertices in the input graph is less than or equal to 20. Input format: This is a sample input from a user. 4 12 0 1 2 0 3 7 0 2 5 1 0 2 1 2 8 1 3 3 2 0...
Write Insertion Sort and Bubble Sort Program for C# also write their algorithm and Explain their...
Write Insertion Sort and Bubble Sort Program for C# also write their algorithm and Explain their working.
How do I create this program? Using C++ language! Write a program that reads data from...
How do I create this program? Using C++ language! Write a program that reads data from a text file. Include in this program functions that calculate the mean and the standard deviation. Make sure that the only global varibles are the mean, standard deviation, and the number of data entered. All other varibles must be local to the function. At the top of the program make sure you use functional prototypes instead of writing each function before the main function....ALL...
Write a MIPS program that uses an implementation of quick sort to sort an array of...
Write a MIPS program that uses an implementation of quick sort to sort an array of numbers (Translate the following code into (Mars Assembly language). Quicksort Implementation - C int partition(int arr [] , int left , int right) { int i=left, j=right; int tmp; int pivot = arr[(left + right) / 2]; while (i <= j) { while (arr [ i ] < pivot) i ++; while (arr [ j ] > pivot) j −−; if (i <= j)...
Write a very general sort method that can sort any type of data arrays/lists. For example,...
Write a very general sort method that can sort any type of data arrays/lists. For example, can sort a list of integers in ascending order, a list of integers in descending order, a list of doubles, a list of student objects (with names and scores) in ascending order of names, or in descending order of scores, … You can use any pre-defined sort function or can code your own. Use your favorite language for implementation. If your language doesn’t support...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT