Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 Store data in array
#1
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 :)
Quote
#2
Try list(reader).
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures

Quote
#3
Thanks for answer!

Where would you use the list(reader)?
Quote
#4
Right after line 10. Then you can pretty much delete everything else. That will give you the data in an array (list).
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures

Quote
#5
Ah cool! Thank you :) :) :)
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  Using Data from an Array Tomington 1 250 Apr-06-2019, 10:42 AM
Last Post: perfringo
  Call out data from 2D array to perform calculation poonck1 1 1,291 Feb-28-2017, 01:53 PM
Last Post: buran
  How to extract two data types from a text file and store them as two separate lists banf 1 1,395 Jan-16-2017, 09:52 PM
Last Post: Larz60+

Forum Jump:


Users browsing this thread: 1 Guest(s)