Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- altura = np.loadtxt("bio.dat",delimiter=',',usecols=(5,),dtype='float')
- File "/usr/lib/python2.7/dist-packages/numpy/lib/npyio.py", line 846, in loadtxt
- vals = [vals[i] for i in usecols]
- IndexError: list index out of range
- import numpy as np
- altura = np.loadtxt("bio.dat",delimiter=',',usecols=(5,),dtype='str')
- print altura
- 1 Katherine Oquendo M 18 1.50 50
- 2 Pablo Restrepo H 20 1.83 79
- 3 Ana Agudelo M 18 1.58 45
- 4 Kevin Vargas H 20 1.74 80
- 5 Pablo madrid H 20 1.70 55
- x=sum(altura)
- import csv
- txt_file = r"mytxt.txt"
- csv_file = r"mycsv.csv"
- # use 'with' if the program isn't going to immediately terminate
- # so you don't leave files open
- # the 'b' is necessary on Windows
- # it prevents x1a, Ctrl-z, from ending the stream prematurely
- # and also stops Python converting to / from different line terminators
- # On other platforms, it has no effect
- in_txt = csv.reader(open(txt_file, "rb"), delimiter = 't')
- out_csv = csv.writer(open(csv_file, 'wb'))
- out_csv.writerows(in_txt)
- In [17]: from StringIO import StringIO
- In [18]: s="""
- 1 Katherine Oquendo M 18 1.50 50
- 2 Pablo Restrepo H 20 1.83 79
- 3 Ana Agudelo M 18 1.58 45
- 4 Kevin Vargas H 20 1.74 80
- 5 Pablo madrid H 20 1.70 55
- """
- In [19]: S=StringIO(s)
- In [20]: data=np.loadtxt(S,dtype=float,usecols=(5,))
- In [21]: data
- Out[21]: array([ 1.5 , 1.83, 1.58, 1.74, 1.7 ])
- In [22]: np.sum(data)
- Out[22]: 8.3499999999999996
- import numpy as np
- fname = 'stack25828405.txt'
- data=np.loadtxt(fname,dtype=float,usecols=(5,))
- print data
- print np.sum(data)
- 2119:~/mypy$ python2.7 stack25828405.py
- [ 1.5 1.83 1.58 1.74 1.7 ]
- 8.35
- altura = np.loadtxt("bio.dat",delimiter=',',usecols=(5,),dtype=βstrβ,comments='')
Add Comment
Please, Sign In to add comment