473,406 Members | 2,713 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,406 software developers and data experts.

Re: maximum value in a column of file

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>

Jul 23 '08 #1
0 1517

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?
1
by: maurizio | last post by:
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...
1
by: Fredrik Lundh | last post by:
maurizio wrote: 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...
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.