Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #9437 > unrolled thread

Re: losing-end-of-row values when manipulating CSV input

Started byEthan Furman <ethan@stoneleaf.us>
First post2011-07-13 14:17 -0700
Last post2011-07-13 14:17 -0700
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: losing-end-of-row values when manipulating CSV input Ethan Furman <ethan@stoneleaf.us> - 2011-07-13 14:17 -0700

#9437 — Re: losing-end-of-row values when manipulating CSV input

FromEthan Furman <ethan@stoneleaf.us>
Date2011-07-13 14:17 -0700
SubjectRe: losing-end-of-row values when manipulating CSV input
Message-ID<mailman.1001.1310591050.1164.python-list@python.org>
Neil Berg wrote:
> Hello all,
> 
> I am having an issue with my attempts to accurately filter some data from a CSV file I am importing.  I have attached both a sample of the CSV data and my script.  
> 
> The attached CSV file contains two rows and 27 columns of data.  The first column is the station ID "BLS", the second column is the sensor number "4", the third column is the date, and the remaining 24 columns are hourly temperature readings. 
> 
> In my attached script, I read in row[3:] to extract just the temperatures, do a sanity check to make sure there are 24 values, remove any missing or "m" values, and then append the non-missing values into the "hour_list".  
> 
> Strangely the the first seven rows appear to be empty after reading into the CSV file, so that's what I had to incorporate the if len(temps) == 24 statement.  
> 
> But the real issue is that for days with no missing values, for example the second row of data, the length of the hour_list should be 24.  My script, however, is returning 23.  I think this is because the end-of-row-values have a trailing "\". This must mark these numbers as non-digits and are lost in my "isdig" filter line.  I've tried several ways to remove this trailing "\", but to no success. 
> 
> Do you have any suggestions on how to fix this issue?
> 
> Many thanks in advance,
> 
> Neil Berg
> 
> 
Your 'csv' file isn't -- it looks like rich text.  An actual csv file 
looks more like this (which is probably what you're seeing in notepad, 
but is not what is stored on disk):

8<------------------------------------------------------------------------------------
BLS,4,19981101,37,m,36,34,36,35,34,34,35,36,38,39,43,42,42,42,38,36,34,32,33,33,35,34
BLS,4,19981102,34,32,33,32,34,32,33,32,34,38,40,41,44,47,43,42,39,36,35,35,36,36,35,33
8<------------------------------------------------------------------------------------

Try saving in text-only format.

~Ethan~

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web