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


Groups > comp.lang.python > #9437

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

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!feeder.news-service.com!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <ethan@stoneleaf.us>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.000
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'advance,': 0.07; 'sanity': 0.07; 'script,': 0.07; 'subject:when': 0.07; 'append': 0.09; 'csv': 0.09; 'from:addr:ethan': 0.09; 'from:addr:stoneleaf.us': 0.09; 'from:name:ethan furman': 0.09; 'issue?': 0.09; 'message- id:@stoneleaf.us': 0.09; 'received:gator410.hostgator.com': 0.09; 'statement.': 0.09; 'trailing': 0.09; '~ethan~': 0.09; 'stored': 0.13; 'wrote:': 0.15; '"m"': 0.16; 'columns': 0.16; 'received:72.11': 0.16; 'received:72.11.125': 0.16; 'received:72.11.125.166': 0.16; 'row': 0.16; 'rows': 0.16; 'strangely': 0.16; 'subject:CSV': 0.16; 'subject:manipulating': 0.16; 'cc:addr:python-list': 0.16; 'script.': 0.19; '(which': 0.20; 'cc:2**0': 0.21; 'column': 0.22; 'file,': 0.22; 'filter': 0.22; 'cc:no real name:2**0': 0.22; 'header:In-Reply-To:1': 0.22; 'hourly': 0.23; 'appear': 0.23; 'extract': 0.25; 'tried': 0.27; 'seeing': 0.28; 'all,': 0.28; 'fix': 0.29; 'second': 0.29; 'cc:addr:python.org': 0.30; 'example': 0.30; 'values,': 0.30; 'looks': 0.30; 'thanks': 0.31; 'values': 0.31; 'remaining': 0.32; "i've": 0.33; 'header:User-Agent:1': 0.34; 'there': 0.34; 'however,': 0.34; "isn't": 0.35; 'probably': 0.35; 'actual': 0.35; 'data,': 0.35; 'format.': 0.35; 'file': 0.36; 'data.': 0.36; 'issue': 0.37; 'date,': 0.37; 'some': 0.37; 'but': 0.37; 'several': 0.37; 'subject:: ': 0.38; 'returning': 0.38; 'think': 0.38; 'two': 0.38; 'should': 0.39; 'data': 0.39; 'ways': 0.39; 'missing': 0.40; 'mark': 0.40; 'third': 0.40; 'your': 0.60; 'received:websitewelcome.com': 0.65; 'received:184': 0.67; 'lost': 0.73; 'saving': 0.74; 'station': 0.82; 'notepad,': 0.84; 'temperature': 0.93
Date Wed, 13 Jul 2011 14:17:41 -0700
From Ethan Furman <ethan@stoneleaf.us>
User-Agent Thunderbird 1.5.0.10 (Windows/20070221)
MIME-Version 1.0
To Neil Berg <nberg@atmos.ucla.edu>
Subject Re: losing-end-of-row values when manipulating CSV input
References <CC0B2F67-6C7A-4D29-9B07-508C37EDE6F6@atmos.ucla.edu>
In-Reply-To <CC0B2F67-6C7A-4D29-9B07-508C37EDE6F6@atmos.ucla.edu>
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
X-AntiAbuse This header was added to track abuse, please include it with any abuse report
X-AntiAbuse Primary Hostname - gator410.hostgator.com
X-AntiAbuse Original Domain - python.org
X-AntiAbuse Originator/Caller UID/GID - [47 12] / [47 12]
X-AntiAbuse Sender Address Domain - stoneleaf.us
X-BWhitelist no
X-Source
X-Source-Args
X-Source-Dir
X-Source-Sender mail.admailinc.com ([192.168.10.136]) [72.11.125.166]:4872
X-Source-Auth ethan+stoneleaf.us
X-Email-Count 1
X-Source-Cap dG9idWs7dG9idWs7Z2F0b3I0MTAuaG9zdGdhdG9yLmNvbQ==
Cc python-list@python.org
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.1001.1310591050.1164.python-list@python.org> (permalink)
Lines 32
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1310591050 news.xs4all.nl 23927 [2001:888:2000:d::a6]:58246
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:9437

Show key headers only | View raw


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~

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

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

csiph-web