maximum value in a column of file

bernhard.voigt at bernhard.voigt at
Wed Jul 23 15:30:19 CEST 2008

> > thank you for your answer
> > actually i've to do some statistics (maximum,minimum,mean,standard
> > deviation,....) of a file of data in which each column is a particular
> > type of data. (the file is a tab separated value).
> > I was trying to do this by using python (usually i work with fortran or
> > bash, but i'm learning python), that the reason why i tried to use numpy.

numpy.loadtxt is probably what your looking for, provided your file
contains only numbers and comment lines.
check the example here:

X = numpy.loadtxt('data.txt')
X[:,0].mean() # mean of first column
X[:,0].max() # mux of first column
X[:,0].var() # variance of first column

enjoy! bernhard

> As I implied, you can do all this in standard Python "by hand", but
> numpy/scipy can definitely make things easier.  There's a dependency
> cost here (your program needs one or more extra libraries to work), but
> if that's no problem in your environment, I'd recommend that approach.
> The scipy add-on contains a bunch of things for file i/o; see
> for an overview.  Since you're reading text files, the "array_import"
> module seems to be what you need:
> There are active user communities for both numpy and scipy that can help
> you sort out any remaining issues; for details, see:
> Hope this helps!
> </F>

More information about the Python-list mailing list