Link to home
Start Free TrialLog in
Avatar of merijn van der leek
merijn van der leek

asked on

Finding the longest freezing period in a csv with python.

I wanna know the longest freezing period from a csv.

The format of the csv is this:

01-06 STAID: Station identifier
08-13 SOUID: Source identifier
15-22 DATE : Date YYYYMMDD
24-28 TX   : Maximum temperature in 0.1 °C
30-34 Q_TX : quality code for TX (0='valid'; 1='suspect'; 9='missing')

STAID,SOUID,DATE,TX,Q_TX
162,100522,19010101,-31,0
162,100522,19010102,-13,0
162,100522,19010103,-5,0
162,100522,19010104,-10,0
162,100522,19010105,-18,0
162,100522,19010106,-78,0

Does anyone know a way to find the longest freezing period and print it in the format:

The longest freezingperiod was 12 days and ended on 29 jun 1999. (example)

Any help would be very much appreciated :)
Avatar of Martyn Spencer
Martyn Spencer
Flag of United Kingdom of Great Britain and Northern Ireland image

It looks as though you are initially providing a file format where the columns are fixed widths and then afterwards you show the data in CSV format. CSV is not necessarily fixed width format - they can be different things. Fixed format could well use commas as separators for fields, but it is not necessarily the case. In fact, the reason for using fixed width format is to avoid the need for a delimiter.

That being said, this is the kind of thing a database does really well. I am sure that a spreadsheet could also be used, but it depends on how often you will be doing this.

If it were something that you were going to be doing regularly, perhaps consider importing the data into a database and writing some code to handle the calculation. Alternatively, it would also be possible to create a simple program that would provide the information for you. I note that you tagged this with Python, so perhaps you are asking someone to code a solution for you? What have you tried? This looks rather like a homework question otherwise.
Avatar of merijn van der leek
merijn van der leek

ASKER

He it is a homework question which i am having a hard time with so if u got any ideas coding wise i would love to hear them!
ASKER CERTIFIED SOLUTION
Avatar of aikimark
aikimark
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Given that you say it is a homework question, it would be better for you to ask questions and learn, rather than have us do the work for you. The question linked by aikimark should set you on your way.