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

1
  • you are missing a ) end of first line. Commented Jun 22, 2016 at 3:48

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

I get this error now: ValueError: sequence too large; cannot be greater than 32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.