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


Groups > comp.lang.python > #39330

working with csv module in python

Path csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <insideshoes@gmail.com>
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; 'attribute': 0.05; 'column': 0.07; 'merging': 0.07; 'skip:o 50': 0.07; 'python': 0.09; '"w")': 0.09; 'delimited': 0.09; 'delimiter': 0.09; 'files:': 0.09; 'rows': 0.09; 'skip:o 60': 0.09; 'subject:module': 0.09; 'suggestions.': 0.09; 'advance': 0.10; 'subject:python': 0.11; 'columns': 0.16; 'csv': 0.16; 'prog': 0.16; 'row': 0.16; 'skip:g 50': 0.16; 'writer': 0.16; 'x,y,z': 0.16; 'skip:g 40': 0.17; 'module': 0.19; 'to:name:python-list@python.org': 0.20; 'file.': 0.20; 'written': 0.20; 'trying': 0.21; 'import': 0.21; 'so.': 0.24; 'merge': 0.27; 'message-id:@mail.gmail.com': 0.27; 'skip:& 10': 0.29; 'error': 0.30; 'null': 0.33; 'to:addr:python- list': 0.33; 'skip:& 20': 0.33; 'received:google.com': 0.34; 'text': 0.34; 'thanks': 0.34; 'something': 0.35; 'there': 0.35; 'but': 0.36; 'subject:with': 0.36; 'why': 0.37; 'data': 0.37; 'files': 0.38; 'some': 0.38; 'gives': 0.39; 'to:addr:python.org': 0.39; 'space': 0.39; 'skip:" 10': 0.40; 'your': 0.60; 'first': 0.61; '!!!': 0.62; 'between': 0.63; 'dont': 0.64; 'forward': 0.66; '299': 0.84
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:x-received:date:message-id:subject:from:to :content-type; bh=Y3R1q07pG/kSaJyQXUG5AqD9iZ0jQRXKbdVXpaSUzpU=; b=tcg4swEJyGeN6EdeVNY3G4aNGOinC3bNC5z3SuFMqghhgKKuF3bLGGfVspkKn2LeR3 oYYY6+ptpvmq0PAu8hMp7rtH8X51b77XZpUhpF8KvIZoYNKqUzXabcQgrNIly84/rObF NC/QvduoNppW/GaBFUZMSXhw6s0wzVAfVXeBWt2BvGMyLgADuBSsbE4pQtpA1aE2pLdV EcUgSGlzT/T7oZMyJBr3XsZiZaVqIYm9X1gxq6kDGDtdn5l471sYiX0UMoUsDQ7dSVYf b+HsSJ/bYTJchMB+eSdepemPKo5SIJyC/w+6dLdVze2PGT4ZKRFI6ZDsZN9iDWZ5i5hk TMEw==
MIME-Version 1.0
X-Received by 10.50.33.203 with SMTP id t11mr9987339igi.97.1361353854773; Wed, 20 Feb 2013 01:50:54 -0800 (PST)
Date Wed, 20 Feb 2013 10:50:54 +0100
Subject working with csv module in python
From inshu chauhan <insideshoes@gmail.com>
To "python-list@python.org" <python-list@python.org>
Content-Type multipart/alternative; boundary=f46d044788dbed69db04d624e428
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.2093.1361353864.2939.python-list@python.org> (permalink)
Lines 81
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1361353864 news.xs4all.nl 6873 [2001:888:2000:d::a6]:50097
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:39330

Show key headers only | View raw


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

I have 10 simple text files with 3 columns x,y,z delimited by "space". I am
trying to combine these 10 files to get a single text file.

Eg. of data in 10 files is
299 446 2


I had written this prog for merging files:


import csv
import glob

with open(r"C:\Users\inshu.chauhan\Desktop\test2.arff", "w") as w:
    writer = csv.writer(w, delimiter = ' ', quotechar = ' ' ,quoting =
csv.QUOTE_MINIMAL)
    for f in glob.glob(r"C:\Users\inshu.chauhan\Desktop\For
Model_600\*.arff"):
        rows = open(f, "r").readlines()
        writer.writerows(rows)



But the result after merging the files is not I need , it is something like
:
2 9 9      4 4 6      2


2 9 9      4 4 7      2


2 9 9      4 4 8      2


2 9 8      4 4 9      2


Can in some some way I set delimiter to NULL as the prog gives me error if
I do so. I dont why there is space between the attribute of first column in
reading and there is space between every row too..

Or can I merge these text files without using csv module , directly in
python ?

Looking forward to your suggestions.

Thanks in advance !!!

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


Thread

working with csv module in python inshu chauhan <insideshoes@gmail.com> - 2013-02-20 10:50 +0100

csiph-web