how do i filter through a CSV file and group the values without the use of any type of imports

  csv, python, python-3.x

My project requires me to have a main function called
def main(csvfile,country,type):

I am going to explain the project requirements so that I can understand how to begin this project. The project requires me to find minimum, maximum, standard deviation and correlation of the number of positive covid cases in EACH country for EACH month. In this case positive cases = new cases in the csvfile. The main function will be used to test the whole Python script for checking the test cases. There is a complexity with TYPE as:

type is the input argument which mentions which type of analysis are required. It can take
only one of the two string inputs: “statistics” or “correlation”. If third input
argument is “statistics”, then the objective of the program is to find the statistical
analysis of a single country. Otherwise if the third input argument is “correlation” then
the objective of the program is to find the correlation of statistical data of two countries.

so far this is the code I have written :

def main(csvfile,country,type):
    try:
        Fileopen = open(csvfile,"r")                                                             #code opens the csv file 
        Fileread = Fileopen.read()
        Filelines = Fileread.split("n")                                                          #splits the list with a new line
        listname = []
    
        for line in Filelines:
            Filevalues = line.split(",")                                                          #splits the  list with a comma 
            listname.append(Filevalues)
            
        for index in range (len(listname)):                                                       #loop checks and removes any empty lists from the csv
            if listname[index] == ['']:
                listname.pop(index)

    except FileNotFoundError:
        print('please check if the name of the file is correct')
        quit()

Hence, I am confused on how to begin with filtering the csvfile with each country with the number of cases for each month and then finding the min/max and so on. Just need a little guide.

How the csvfile looks like

Source: Python-3x Questions

LEAVE A COMMENT