473,387 Members | 3,750 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Re: Re: maximum value in a column of file

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.

Fredrik Lundh wrote:
<div class="moz-text-flowed" style="font-family: -moz-fixed">maurizio
wrote:
>i tryed to use the module max of numpy,
the problem is that i don't know how to put the column of the file in
an array.
(i'm new in phyton).
anyway if you think there is a better way.....

What kind of file is it? Did you pick numpy because you want to do
matrix operations (beyond just finding a maximum value), or was it
just the first thing you stumbled upon when researching the problem?

A simple pattern for finding the maximum value in a file, using only
plain Python code, is:

max_value = ... some very small value ...
for line in file:
value = ... extract value from line ...
if value max_value:
max_value = value

If it's not obvious what "some very small value" is, given the range
of data you're working with, you can do

max_value = None
for line in file:
value = ... extract value from line ...
if max_value is None or value max_value:
max_value = value

instead (this leaves max_value set to None if the file is empty)

A more experienced Python hacker might write

def get_all_values(file):
for line in file:
value = ... extract value from line ...
yield value

...

max_value = max(get_all_values(file))

instead. But this still leaves us with the problem of extracting the
value. The best way to do that depends on the kind of files you're
working with; for fixed-format text files, you could use string
slicing and int/float for conversion (e.g. "value =
float(line[10:20])", see the tutorial for details); for other text
formats, you could use split/partition or regular expressions, or
maybe an existing module (such as "csv"); for binary formats, there's
a large
number of existing tools.

And if you really want to use numpy for other reasons than just
getting a maximum value from a column, there's plenty of stuff in
NumPy and SciPy (http://www.scipy.org/) that might be useful.

So, in other words, I guess we still need more info.

</F>
</div>
Jul 23 '08 #1
1 3348
maurizio wrote:
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.
Look into the csv module (comma separated values). It also can deal
with tab separated values.

--Scott David Daniels
Sc***********@Acm.Org
Jul 23 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Joe Goh | last post by:
Hi there Does anyone know what is the maximum column length for a table in a MySQL database? I was thinking of storing feedback in the form of text in the database. How feasible is this? Would...
2
by: Hennie de Nooijer | last post by:
I have a problem (who not?) with a function which i'm using in a view. This function is a function which calculates a integer value of a date. For example: '12/31/2004 00:00:00" becomes 20041231....
2
by: Hennie de Nooijer | last post by:
Because of an error in google or underlying site i can reply on my own issue. Therefore i copied the former entered message in this message....
2
by: Roger Withnell | last post by:
How do I find the maximum value of a recordset column? I'd rather do it this way than open a new recordset with Max(column). Thanks in anticipation. Posted Via Usenet.com Premium Usenet...
2
by: Kums | last post by:
What is the maximum permissible size of a database? Is there any limitation. What is the maximum # of tablespace's allowed in a database? Thanks for your response.
1
by: maurizio | last post by:
which is the best way for the calculation of the maximum value in a column of a file?
0
by: maurizio | last post by:
i tryed to use the module max of numpy, the problem is that i don't know how to put the column of the file in an array. (i'm new in phyton). anyway if you think there is a better way..... ...
0
by: Fredrik Lundh | last post by:
maurizio wrote: What kind of file is it? Did you pick numpy because you want to do matrix operations (beyond just finding a maximum value), or was it just the first thing you stumbled upon...
7
by: laredotornado | last post by:
Hi, I'm using PHP 5 with MySql 5. I have a MySQL InnoDB table with a column of type INTEGER UNSIGNED. Is there a constant in PHP to insert the maximum value possible into the column? The...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.