Re: csv blank fields

2009-06-30 Thread norseman
Mag Gam wrote: I am using the csv package to parse a compressed .csv.gz file. So far its working perfectly fine but it fails when I have a missing value in on of the fields. For example, I have this Abc,def,,jkl Is it possible to fill the missing column with a null? I want, Abc,def,NULL,jkl

Re: csv blank fields

2009-06-29 Thread Mag Gam
Thankyou! On Tue, Jun 30, 2009 at 12:17 AM, Chris Rebert wrote: > On Mon, Jun 29, 2009 at 8:47 PM, Lawrence > D'Oliveiro wrote: >> In message , MRAB >> wrote: >> >>>      row = [r or "NULL" for r in row] >> >> I know that, in this particular case, all the elements of row are strings, >> and the

Re: csv blank fields

2009-06-29 Thread Chris Rebert
On Mon, Jun 29, 2009 at 8:47 PM, Lawrence D'Oliveiro wrote: > In message , MRAB > wrote: > >>      row = [r or "NULL" for r in row] > > I know that, in this particular case, all the elements of row are strings, > and the only string that is equivalent to False is the empty string, but > still > >  

Re: csv blank fields

2009-06-29 Thread Lawrence D'Oliveiro
In message , MRAB wrote: > row = [r or "NULL" for r in row] I know that, in this particular case, all the elements of row are strings, and the only string that is equivalent to False is the empty string, but still row = [[r, "NULL"][r == ""] for r in row] -- http://mail.python.org

Re: csv blank fields

2009-06-27 Thread Peter Otten
Mag Gam wrote: Please don't top-post. > Sorry if I wasn't clear before. > > While reading my csv file, notice I am putting the content in an array. That's already in the code you posted. What's missing is the value of "mtypes". I really meant it when I asked you to provide a self-contained ex

Re: csv blank fields

2009-06-27 Thread MRAB
Mag Gam wrote: Peter: Sorry if I wasn't clear before. While reading my csv file, notice I am putting the content in an array. If lets say, row[5] has nothing in it, python gives an exception. Instead of the exception, I would like to assign 'NULL' to row[5]. Does that help? You still didn't

Re: csv blank fields

2009-06-27 Thread Mag Gam
Peter: Sorry if I wasn't clear before. While reading my csv file, notice I am putting the content in an array. If lets say, row[5] has nothing in it, python gives an exception. Instead of the exception, I would like to assign 'NULL' to row[5]. Does that help? On Sat, Jun 27, 2009 at 10:03 AM,

Re: csv blank fields

2009-06-27 Thread jkv
Mag Gam wrote: > > well, I am actually loading the row into a fixed width array > > > > reader=csv.reader(fs) > > for s,row in enumerate(reader): > > > > t=np.array([(row[0],row[1],row[2],row[3],row[4],row[5],row[6],row[7],row[8],row[9],row[10])],dtype=mtype) > > d[s]=t > > > > > > If there i

Re: csv blank fields

2009-06-27 Thread Peter Otten
Mag Gam wrote: > well, I am actually loading the row into a fixed width array > > reader=csv.reader(fs) > for s,row in enumerate(reader): > t=np.array([(row[0],row[1],row[2],row[3],row[4],row[5],row[6],row[7],row[8],row[9],row[10])],dtype=mtype) > d[s]=t > > > If there is a missing field,

Re: csv blank fields

2009-06-27 Thread Mag Gam
well, I am actually loading the row into a fixed width array reader=csv.reader(fs) for s,row in enumerate(reader): t=np.array([(row[0],row[1],row[2],row[3],row[4],row[5],row[6],row[7],row[8],row[9],row[10])],dtype=mtype) d[s]=t If there is a missing field, I get a problem in one of my rows

Re: csv blank fields

2009-06-27 Thread MRAB
Mag Gam wrote: I am using the csv package to parse a compressed .csv.gz file. So far its working perfectly fine but it fails when I have a missing value in on of the fields. For example, I have this Abc,def,,jkl Is it possible to fill the missing column with a null? I want, Abc,def,NULL,jkl

csv blank fields

2009-06-27 Thread Mag Gam
I am using the csv package to parse a compressed .csv.gz file. So far its working perfectly fine but it fails when I have a missing value in on of the fields. For example, I have this Abc,def,,jkl Is it possible to fill the missing column with a null? I want, Abc,def,NULL,jkl TIA -- http://ma