Alternative to pandas for reading csv/excel files online

After a lot of sleuthing, I found something nifty that doesn’t use any extra packages. I haven’t yet ported everything online to test it, but I thought I would put this here in case anyone else is curious.

The method involves using data.importCondtions, which imports the csv into a bunch of dictionaries (one for each row in the csv file), with keys that correspond to the column headers at the beginning of the csv. Then, all we have to do is a little loop to meld all of these dictionaries together, and voilà, the dictionary is ready to use in the script.

# initialize the big dictionary...
expVars = {}

# import csv file
csvData = data.importConditions('my_file.csv')

# meld all dictionaries together and store in the big one
for k in csvData[0]:
    expVars[k] = [d[k] for d in csvData]

You can now access the dictionary by name and list index; e.g.

expVars['var1'][33]

1 Like