2016-06-22 31 views
1
activity=csv.reader(open('activity(delimited).csv') 
data = np.array([activity]) 
url_data = data[:, 70] 

我想從CSV文件中提取一列。本專欄列出了我想閱讀的網址。但是我每次運行這幾行的時候,我得到: -如何從python的csv文件讀取列的行?

IndexError:太多的指數陣列

+0

你錯過了')'第一行的結尾。 –

回答

0

有一堆在計算器上[post 1]非常相似問題,[post 2

僅供參考,實現此目的有一種更簡潔的方法。
genfromtxt將很適合您的要求。從文檔,

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.

你需要做這樣的事情。

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

鑑於您的是csv,分隔符是,

my_data現在應該保持numpy ndarray

+0

我現在得到這個錯誤:ValueError:序列太大;不能大於32 – Technologic27