Reading and Organizing a CSV without modules?

I have multiple different csv files that have a different number of headers. I need to read these csv's without using any modules so I have given it an attempt. How would I print the columns of the different csv's and then be able to get the mean, min, max and standard deviation for each of them, as well as plot them against each other?

Here is what I have so far but in this case the lists have been hard coded in. In this case the file I am reading into it has 2 headers for the date-time and barometer reading but I am also going to be reading other files that have many more headers and more information.

I can use pandas once I have written the csv into a python dataframe so that is why I have imported it. Any recommendations or ideas are much appreciated. Thanks!

import pandas as pd

def readmyfile(InputFile):
    
    list_date = []
    list_baro = []
    
    with open(InputFile, 'r') as file:
        for line in file:
            row = line.split(',')
            list_date.append(row[0].strip('"'))
            list_baro.append(row[1].strip('\n'))
    
#     df = pd.DataFrame(list_date[1:])
#     df2 = pd.DataFrame(list_baro[1:])
#     average = np.mean(df2)
    
    print(list_date)
    print(list_baro)
    
readmyfile('barometer-last-year.csv')

Some of the data that is in the barometer-last-year.csv:

"DateTime","Baro"
"2016-10-09 00:00:00",1021.9
"2016-10-10 00:00:00",1019.9
"2016-10-11 00:00:00",1015.8
"2016-10-12 00:00:00",1013.2
"2016-10-13 00:00:00",1005.9
"2016-10-14 00:00:00",998.6
"2016-10-15 00:00:00",998
"2016-10-16 00:00:00",1002.2
"2016-10-17 00:00:00",1009.8
"2016-10-18 00:00:00",1013.4
"2016-10-19 00:00:00",1015.8
"2016-10-20 00:00:00",1015.7

and here is some of the data that I have in the other csv's:

"DateTime","Temperature","Temperature_range (low)","Temperature_range (high)"
"2016-10-09 00:00:00",10.66,7.2,13.8
"2016-10-10 00:00:00",8.94,5.6,12.8
"2016-10-11 00:00:00",8.69,5.3,14.3
"2016-10-12 00:00:00",11.55,9,14.9
"2016-10-13 00:00:00",9.4,6,13.3
"2016-10-14 00:00:00",9.85,6.8,13.3
"2016-10-15 00:00:00",10.72,8.2,14.7
"2016-10-16 00:00:00",11.28,7.8,14.5
"2016-10-17 00:00:00",11.84,10,15
"2016-10-18 00:00:00",10.24,8.2,12.7
"2016-10-19 00:00:00",10.2,8,13.4
"2016-10-20 00:00:00",9.76,7.2,12.8
"2016-10-21 00:00:00",7.96,3.7,15.1
"2016-10-22 00:00:00",7.9,5.3,13


Read more here: https://stackoverflow.com/questions/64403398/reading-and-organizing-a-csv-without-modules

Content Attribution

This content was originally published by Nhyi at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: