Re: working with csv module in python

Discussion in 'Python' started by Roland Koebler, Feb 20, 2013.

  1. Hi,

    On Wed, Feb 20, 2013 at 10:50:54AM +0100, inshu chauhan wrote:
    > 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

    Do you only want to concat the files, or do you want to parse/mangle
    them?

    If you only want to concat the files, I would use some shell-tools,
    like "cat" on Linux or "copy" on Windows, so

    copy C:\Users\inshu.chauhan\Desktop\ForModel_600\*.arff C:\Users\inshu.chauhan\Desktop\test2.arff

    should do it.

    > Can in some some way I set delimiter to NULL as the prog gives me error if
    > I do so.

    Of course -- a CSV without a delimiter doesn't make any sense.

    > I dont why there is space between the attribute of first column in
    > reading and there is space between every row too..

    Because there's a "split()" missing in your code. You currently tell the
    CSV-writer to write the columns 2,9,9, , , ,4,4,6, , , ,2 as
    space-separated CSV. So, try something like
    rows = [r.split() for r in open(f, "r").readlines()]

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

    If you don't need to parse/mangle the contents, you don't need the csv
    module. Simple open the resulting file for writing, and then read out
    the source files and write their contents into the resulting file.


    regards
    Roland
     
    Roland Koebler, Feb 20, 2013
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Daniel Ortmann
    Replies:
    4
    Views:
    609
    Skip Montanaro
    Jul 2, 2003
  2. jliu66
    Replies:
    0
    Views:
    566
    jliu66
    Oct 19, 2007
  3. Peter Otten

    Re: working with csv module in python

    Peter Otten, Feb 20, 2013, in forum: Python
    Replies:
    0
    Views:
    180
    Peter Otten
    Feb 20, 2013
  4. Dave Angel

    Re: working with csv module in python

    Dave Angel, Feb 20, 2013, in forum: Python
    Replies:
    0
    Views:
    157
    Dave Angel
    Feb 20, 2013
  5. Dave Angel

    Re: working with csv module in python

    Dave Angel, Feb 20, 2013, in forum: Python
    Replies:
    0
    Views:
    159
    Dave Angel
    Feb 20, 2013
Loading...

Share This Page