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


Groups > comp.lang.python > #40162

Re: Read csv file and create a new file

Path csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder2.hal-mli.net!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <davea@davea.name>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.002
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'example:': 0.03; '-----------': 0.04; '------------': 0.07; 'subject:file': 0.07; 'excluding': 0.09; 'subject:create': 0.09; 'files.': 0.13; 'resulting': 0.13; '(the': 0.15; 'csv': 0.16; 'one)': 0.16; 'row': 0.16; 'wrote:': 0.17; 'file.': 0.20; 'file:': 0.22; 'second': 0.24; 'header:In-Reply-To:1': 0.25; 'header:User-Agent:1': 0.26; 'values': 0.26; 'plain': 0.27; 'whitespace': 0.29; 'skip:- 30': 0.31; 'file': 0.32; 'like:': 0.33; 'anyone': 0.33; 'to:addr :python-list': 0.33; 'hi,': 0.33; 'text': 0.34; 'third': 0.34; 'thanks': 0.34; 'pm,': 0.35; 'something': 0.35; 'test': 0.36; 'data': 0.37; 'subject:: ': 0.38; 'to:addr:python.org': 0.39; 'received:192': 0.39; 'where': 0.40; 'received:192.168': 0.40; 'help': 0.40; 'remove': 0.61; 'first': 0.61; 'making': 0.64; 'received:74.208': 0.71
Date Thu, 28 Feb 2013 14:35:37 -0500
From Dave Angel <davea@davea.name>
User-Agent Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130106 Thunderbird/17.0.2
MIME-Version 1.0
To python-list@python.org
Subject Re: Read csv file and create a new file
References <512fac9c$0$40355$4fafbaef@reader1.news.tin.it>
In-Reply-To <512fac9c$0$40355$4fafbaef@reader1.news.tin.it>
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
X-Provags-ID V02:K0:hAWPyyFquzZ1fb0RiAzLS2tTyvhUq2AxUxWhR0EpidX wVcH/7YBf/zRiAHnZnXbEv2MvdCW8WaBoe+//AKDc6mmOI1fYp QKnBfLFsBbe5BX8I5C7vEqPurmpjM9Nk1FUGyCeMWP4vqy4dBQ ZWaaKGIru23SM2TiKq9qwizemDDjtSuaE3fRdeJvmOIMvv2FZM dS0vYLbE82eqrC1h4fbnTv3b80i1zxXY3KrsyQv9sZVFnSh6Xi DCtJnFbAlwWVhQ15kd3N10MfYBXlJoeoLdslH9SqjswuSIfjMb zBLL+6CjATUe2VM1Ho5sb9KL4Fo4xRSdzOjlNd7wqCsDvgNXw= =
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
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.2669.1362080157.2939.python-list@python.org> (permalink)
Lines 53
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1362080157 news.xs4all.nl 6870 [2001:888:2000:d::a6]:44827
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:40162

Show key headers only | View raw


On 02/28/2013 02:14 PM, io wrote:
> Hi,
>
> i have to files.
>
> First file is a csv file
> Second file is a plain text file where each row has a value (text)
>
> I want to be able to create a third file using data from the first file
> excluding the values listed in the second file.
>
> Example:
>
> First file:
> -----------
>
> mtgoxeur	12	24	36
> mtgoxusd	10	12	14
> mtgoxpln	2	4	6
>
>
> Second file:
> ------------
>
> mtgoxusd
>
>
>
> Third File (the resulting one) :
> --------------------------------
>
> mtgoxeur	12	24	36
> mtgoxpln	2	4	6
>
>
>
> Thanks to anyone that can help
>
>


Start by making a set out of the second file.  Don't forget to remove 
whitespace with strip()

Then loop through the first file.  For each line, split() it by 
whitespace, and conditionally write the line to the third file.  The 
test would be something like:
      if  fields[0] in myset:
            outfile.write(line)


-- 
DaveA

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


Thread

Read csv file and create a new file io <maroso@libero.it> - 2013-02-28 19:14 +0000
  Re: Read csv file and create a new file Neil Cerutti <neilc@norwich.edu> - 2013-02-28 19:32 +0000
  Re: Read csv file and create a new file Joel Goldstick <joel.goldstick@gmail.com> - 2013-02-28 14:34 -0500
  Re: Read csv file and create a new file Dave Angel <davea@davea.name> - 2013-02-28 14:35 -0500
  Re: Read csv file and create a new file io <maroso@libero.it> - 2013-02-28 19:51 +0000
    Re: Read csv file and create a new file Neil Cerutti <neilc@norwich.edu> - 2013-02-28 20:11 +0000
      Re: Read csv file and create a new file io <maroso@libero.it> - 2013-02-28 20:23 +0000
        Re: Read csv file and create a new file io <maroso@libero.it> - 2013-02-28 20:46 +0000
          Re: Read csv file and create a new file io <maroso@libero.it> - 2013-02-28 20:51 +0000
          Re: Read csv file and create a new file Dave Angel <davea@davea.name> - 2013-02-28 16:23 -0500
            Re: Read csv file and create a new file io <maroso@libero.it> - 2013-02-28 22:05 +0000
              Re: Read csv file and create a new file Dave Angel <davea@davea.name> - 2013-02-28 19:13 -0500
  Re: Read csv file and create a new file Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2013-02-28 21:04 -0500
    Re: Read csv file and create a new file io <maroso@libero.it> - 2013-03-04 19:04 +0000
      Re: Read csv file and create a new file Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-03-04 23:58 +0000

csiph-web