maximum value in a column of file

bernhard.voigt at gmail.com bernhard.voigt at gmail.com
Wed Jul 23 09:30:19 EDT 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: http://www.scipy.org/Numpy_Example_List_With_Doc#head-88ade192dacf0c15e4f1377096134ee559df07a0

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
>
>      http://www.scipy.org/doc/api_docs/SciPy.io.html
>
> for an overview.  Since you're reading text files, the "array_import"
> module seems to be what you need:
>
>      http://www.scipy.org/doc/api_docs/SciPy.io.array_import.html
>
> There are active user communities for both numpy and scipy that can help
> you sort out any remaining issues; for details, see:
>
>      http://www.scipy.org/Mailing_Lists
>
> Hope this helps!
>
> </F>




More information about the Python-list mailing list