Python Forum
Store data in array - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Homework (https://python-forum.io/forum-9.html)
+--- Thread: Store data in array (/thread-21475.html)



Store data in array - kasper1903 - Oct-01-2019

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 :)


RE: Store data in array - ichabod801 - Oct-01-2019

Try list(reader).


RE: Store data in array - kasper1903 - Oct-04-2019

Thanks for answer!

Where would you use the list(reader)?


RE: Store data in array - ichabod801 - Oct-04-2019

Right after line 10. Then you can pretty much delete everything else. That will give you the data in an array (list).


RE: Store data in array - kasper1903 - Oct-04-2019

Ah cool! Thank you :) :) :)