Python Forum

Full Version: Store data in array
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi guys.

I have some trouble with this code. I want to store my data from a csv into an array - The data consist both of text, dates and numbers.

import csv

timestamp = []
shoeSize = []
program = []
height = []
why = []

with open('Data.csv', delimiter=';') as f:
    reader = csv.reader(f)
    for row in reader:
        timestamp.append[row[0]]
        shoeSize.append[row[1]]
        program.append[row[2]]
        height.append[row[3]]
        why.append[row[4]]

print(timestamp)
It returns the mistake: value is unsubscriptable python

As I understand, it is because of the different types of datapoint it tries to store and it can only stores floats?
How would you guys store data in an array, if it consist of different datatypes ?

Thank you :)
Try list(reader).
Thanks for answer!

Where would you use the list(reader)?
Right after line 10. Then you can pretty much delete everything else. That will give you the data in an array (list).
Ah cool! Thank you :) :) :)