Python Forum
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 :)
Reply
#2
Try list(reader).
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply
#3
Thanks for answer!

Where would you use the list(reader)?
Reply
#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
Reply
#5
Ah cool! Thank you :) :) :)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Newbie here. Create an array from file data? Rayj00 2 1,198 Jan-13-2023, 01:35 PM
Last Post: perfringo
  Read data from a CSV file in S3 bucket and store it in a dictionary in python Rupini 3 6,880 May-15-2020, 04:57 PM
Last Post: snippsat
  Using Data from an Array Tomington 1 2,347 Apr-06-2019, 10:42 AM
Last Post: perfringo
  Call out data from 2D array to perform calculation poonck1 1 3,258 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 3,448 Jan-16-2017, 09:52 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020