我在OS X 10.8终端中运行以下Python脚本,行长度约为200个字符。但是,脚本的输出包含在大约80行。 如何使输出线继续直到控制台的长度?
这是我的Python脚本:
import csv as csv
import numpy as np
#Open up the csv file in to a Python object
csv_file_object = csv.reader(open('./data/train.csv', 'rb'))
header = csv_file_object.next() #The next() command just skips the
#first line which is a header
data=[] #Create a variable called 'data'
for row in csv_file_object: #Run through each row in the csv file
data.append(row) #adding each row to the data variable
data = np.array(data) #Then convert from a list to an array
#Be aware that each item is currently a string in this format
for datum in data:
print datum[0:10]
我得到的输出是:
['1' '3' 'Najib, Miss. Adele Kiamie "Jane"' 'female' '15' '0' '0' '2667'
'7.225' '']
['0' '3' 'Gustafsson, Mr. Alfred Ossian' 'male' '20' '0' '0' '7534'
'9.8458' '']
答案 0 :(得分:1)
这是一个numpy数组表示的设置,为了让它成为整行,你必须用datum
打印每个str.join
。