python - TypeError: list indices must be integers, not tuple -


my code:`

#!/usr/bin/python  open("a.dat", "r") ins:     array = []     line in ins:         l=line.strip()         array.append(l)  a1 = array[:,1] print a1 

i want read a.dat array take first column.what wrong?

for loading numerical data, it's useful use numpy instead of python.

import numpy np arr = np.loadtxt('a.dat') print arr[:,0] 

numpy python library that's suited loading , manipulating numerical data (with bonus when used correctly, it's waaaay faster using python lists). in addition, dealing tabular data mixed datatypes, recommend using pandas.

import pandas pd df = pd.load_csv('a.dat', sep=' ', names=['col1', 'col2']) print df['col1'] 

numpy can found here

pandas can found here


Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -