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


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

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

Started byNeil Berg <nberg@atmos.ucla.edu>
First post2011-07-13 13:22 -0700
Last post2011-07-13 13:42 -0700
Articles 3 — 2 participants

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


Contents

  losing-end-of-row values when manipulating CSV input Neil Berg <nberg@atmos.ucla.edu> - 2011-07-13 13:22 -0700
    Re: losing-end-of-row values when manipulating CSV input Marco Nawijn <nawijn@gmail.com> - 2011-07-13 13:44 -0700
    Re: losing-end-of-row values when manipulating CSV input Marco Nawijn <nawijn@gmail.com> - 2011-07-13 13:42 -0700

#9433 — losing-end-of-row values when manipulating CSV input

FromNeil Berg <nberg@atmos.ucla.edu>
Date2011-07-13 13:22 -0700
Subjectlosing-end-of-row values when manipulating CSV input
Message-ID<mailman.1000.1310588475.1164.python-list@python.org>

[Multipart message — attachments visible in raw view] — view raw

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

[toc] | [next] | [standalone]


#9435

FromMarco Nawijn <nawijn@gmail.com>
Date2011-07-13 13:44 -0700
Message-ID<d87b1cf6-adb5-495c-a84f-acd28c9487c9@z39g2000yqz.googlegroups.com>
In reply to#9433
On Jul 13, 10:22 pm, Neil Berg <nb...@atmos.ucla.edu> 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
>
>  csv_test.py
> 1KViewDownload
>
>  csv_sample.csv
> < 1KViewDownload

Dear Neil,

Don't know if this is a double post (previous post seems to be gone),
but val = val.rstrip('\\') should fix your problem. Note the double
backslash.

Kind regards,

Marco

[toc] | [prev] | [next] | [standalone]


#9443

FromMarco Nawijn <nawijn@gmail.com>
Date2011-07-13 13:42 -0700
Message-ID<cd8f694c-ce7c-47c8-bda9-f73e611f0a4d@p31g2000vbs.googlegroups.com>
In reply to#9433
On Jul 13, 10:22 pm, Neil Berg <nb...@atmos.ucla.edu> 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
>
>  csv_test.py
> 1KViewDownload
>
>  csv_sample.csv
> < 1KViewDownload

Hello Neil,

I just had a quick look at your script. To remove the trailing "\" you
can use val = val.rstrip('\\') in your script. Note the double
backslash.

The script now returns 24 items in the hour_list.

Good luck!

Marco

[toc] | [prev] | [standalone]


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


csiph-web