Find the min max and average of one column of data in python
Posted
by
user1440194
on Stack Overflow
See other posts from Stack Overflow
or by user1440194
Published on 2012-06-06T16:35:26Z
Indexed on
2012/06/06
16:40 UTC
Read the original article
Hit count: 332
python
I have a set of data that looks like this
201206040210 -3461.00000000 -8134.00000000 -4514.00000000 -4394.00000000 0 201206040211 -3580.00000000 -7967.00000000 -4614.00000000 -7876.00000000 0 201206040212 -3031.00000000 -9989.00000000 -9989.00000000 -3419.00000000 0 201206040213 -1199.00000000 -6961.00000000 -3798.00000000 -5822.00000000 0 201206040214 -2940.00000000 -5524.00000000 -5492.00000000 -3394.00000000 0
I want to take the second to last column and find the min, max, and average. Im a little confused on how to use split when the columns are delimited by a space and -. i Figure once i do that i can use min() and max function. I have written a shell script to do the same here
#!/bin/ksh
awk '{print substr($5,2);}' data' > /data1
sort -n data1 > data2
tail -1 data2
head -1 data2
awk '{sum+=$1} END {print "average = ",sum/NR}' data2
Im just not sure how to do this in python. Thanks
© Stack Overflow or respective owner