1
activity=csv.reader(open('activity(delimited).csv')
data = np.array([activity])
url_data = data[:, 70]

I am trying to extract a column from the CSV file. This column has a list of URLs that I would like to read. However every time I run these few lines, I get:-

IndexError: too many indices for array

Technologic27
  • 341
  • 3
  • 4
  • 13

1 Answers1

0

There are a bunch of very similar issues on StackOverflow [post 1], [post 2].

For your reference, there is a much cleaner way of achieving this.
genfromtxt will suit your requirements pretty well. From the documentation,

Load data from a text file, with missing values handled as specified.

Each line past the first skip_header lines is split at the delimiter character, and characters following the comments character are discarded.

You would need to do something like this.

from numpy import genfromtxt
my_data = genfromtxt('activity(delimited)', delimiter=',')

Given that yours is a csv, the delimiter is a ,.

my_data should now hold a numpy ndarray.

Community
  • 1
  • 1
Debosmit Ray
  • 5,228
  • 2
  • 27
  • 43