Re: Finding Blank Columns in CSV

2015-10-07 Thread Jaydip Chakrabarty
On Tue, 06 Oct 2015 20:20:40 +0200, Peter Otten wrote: > Jaydip Chakrabarty wrote: > >> On Tue, 06 Oct 2015 14:33:51 +0200, Peter Otten wrote: >> >>> Jaydip Chakrabarty wrote: >>> On Tue, 06 Oct 2015 01:34:17 +1100, Chris Angelico wrote: > On Tue, Oct 6, 2015 at 1:06 AM, Tim Chas

Re: Finding Blank Columns in CSV

2015-10-07 Thread Peter Otten
Peter Otten wrote: > I really meant it when I asked you to post the code you actually ran, and > the traceback it produces. Anyway, here's a complete script that should work. It uses indices instead names, but the underlying logic is the same. #!/usr/bin/env python import csv import sys from co

Re: Finding Blank Columns in CSV

2015-10-06 Thread Jaydip Chakrabarty
On Tue, 06 Oct 2015 19:25:12 +0100, MRAB wrote: > On 2015-10-06 18:23, Jaydip Chakrabarty wrote: >> On Tue, 06 Oct 2015 14:33:51 +0200, Peter Otten wrote: >> > [snip] >> >> I downloaded gmail contacts in google csv format. There are so many >> columns. So I was trying to create another csv with th

Re: Finding Blank Columns in CSV

2015-10-06 Thread MRAB
On 2015-10-06 18:23, Jaydip Chakrabarty wrote: On Tue, 06 Oct 2015 14:33:51 +0200, Peter Otten wrote: [snip] I downloaded gmail contacts in google csv format. There are so many columns. So I was trying to create another csv with the required columns. Now when I tried to open the gmail csv fil

Re: Finding Blank Columns in CSV

2015-10-06 Thread Peter Otten
Jaydip Chakrabarty wrote: > On Tue, 06 Oct 2015 14:33:51 +0200, Peter Otten wrote: > >> Jaydip Chakrabarty wrote: >> >>> On Tue, 06 Oct 2015 01:34:17 +1100, Chris Angelico wrote: >>> On Tue, Oct 6, 2015 at 1:06 AM, Tim Chase wrote: > That way, if you determine by line 3 that your

Re: Finding Blank Columns in CSV

2015-10-06 Thread Jaydip Chakrabarty
On Tue, 06 Oct 2015 14:33:51 +0200, Peter Otten wrote: > Jaydip Chakrabarty wrote: > >> On Tue, 06 Oct 2015 01:34:17 +1100, Chris Angelico wrote: >> >>> On Tue, Oct 6, 2015 at 1:06 AM, Tim Chase >>> wrote: That way, if you determine by line 3 that your million-row CSV file has no blan

Re: Finding Blank Columns in CSV

2015-10-06 Thread MRAB
On 2015-10-06 12:24, Jaydip Chakrabarty wrote: On Tue, 06 Oct 2015 01:34:17 +1100, Chris Angelico wrote: On Tue, Oct 6, 2015 at 1:06 AM, Tim Chase wrote: That way, if you determine by line 3 that your million-row CSV file has no blank columns, you can get away with not processing all million

Re: Finding Blank Columns in CSV

2015-10-06 Thread Peter Otten
Jaydip Chakrabarty wrote: > On Tue, 06 Oct 2015 01:34:17 +1100, Chris Angelico wrote: > >> On Tue, Oct 6, 2015 at 1:06 AM, Tim Chase >> wrote: >>> That way, if you determine by line 3 that your million-row CSV file has >>> no blank columns, you can get away with not processing all million >>> ro

Re: Finding Blank Columns in CSV

2015-10-06 Thread Jaydip Chakrabarty
On Tue, 06 Oct 2015 01:34:17 +1100, Chris Angelico wrote: > On Tue, Oct 6, 2015 at 1:06 AM, Tim Chase > wrote: >> That way, if you determine by line 3 that your million-row CSV file has >> no blank columns, you can get away with not processing all million >> rows. > > Sure, although that effecti

Re: Finding Blank Columns in CSV

2015-10-05 Thread Denis McMahon
On Mon, 05 Oct 2015 13:29:03 +, Jaydip Chakrabarty wrote: > Hello, > > I have a csv file like this. > > Name,Surname,Age,Sex abc,def,,M ,ghi,,F jkl,mno,, > pqr,,,F > > I want to find out the blank columns, that is, fields where all the > values are blank. Here is my python code. > > fn = "

Re: Finding Blank Columns in CSV

2015-10-05 Thread Friedrich Rentsch
On 10/05/2015 03:29 PM, Jaydip Chakrabarty wrote: Hello, I have a csv file like this. Name,Surname,Age,Sex abc,def,,M ,ghi,,F jkl,mno,, pqr,,,F I want to find out the blank columns, that is, fields where all the values are blank. Here is my python code. fn = "tmp1.csv" fin = open(fn, 'rb')

Re: Finding Blank Columns in CSV

2015-10-05 Thread Chris Angelico
On Tue, Oct 6, 2015 at 1:06 AM, Tim Chase wrote: > That way, if you determine by line 3 that your million-row CSV file > has no blank columns, you can get away with not processing all > million rows. Sure, although that effectively means the entire job is moot. I kinda assume that the OP knows th

Re: Finding Blank Columns in CSV

2015-10-05 Thread Tim Chase
On 2015-10-06 00:51, Chris Angelico wrote: > fn = "tmp1.csv" > fin = open(fn, 'rb') > rdr = csv.DictReader(fin, delimiter=',') > # all the same down to here > blanks = set(rdr.fieldnames) > for row in rdr: > blanks = {col for col in blanks if not row[col]} > mt = [col for col in rdr.fieldnames

Re: Finding Blank Columns in CSV

2015-10-05 Thread Random832
On Mon, Oct 5, 2015, at 09:29, Jaydip Chakrabarty wrote: > Hello, > > I have a csv file like this. > > Name,Surname,Age,Sex > abc,def,,M > ,ghi,,F > jkl,mno,, > pqr,,,F > > I want to find out the blank columns, that is, fields where all the > values are blank. Here is my python code. > > fn =

Re: Finding Blank Columns in CSV

2015-10-05 Thread Chris Angelico
On Tue, Oct 6, 2015 at 12:48 AM, Chris Angelico wrote: > fn = "tmp1.csv" > fin = open(fn, 'rb') > rdr = csv.DictReader(fin, delimiter=',') > # all the same down to here > blanks = set(rdr.fieldnames) > for row in data: > blanks = {col for col in blanks if not row[col]} > mt = [col for col in r

Re: Finding Blank Columns in CSV

2015-10-05 Thread Chris Angelico
On Tue, Oct 6, 2015 at 12:29 AM, Jaydip Chakrabarty wrote: > I want to find out the blank columns, that is, fields where all the > values are blank. Here is my python code. > > fn = "tmp1.csv" > fin = open(fn, 'rb') > rdr = csv.DictReader(fin, delimiter=',') > data = list(rdr) > flds = rdr.fieldna

Finding Blank Columns in CSV

2015-10-05 Thread Jaydip Chakrabarty
Hello, I have a csv file like this. Name,Surname,Age,Sex abc,def,,M ,ghi,,F jkl,mno,, pqr,,,F I want to find out the blank columns, that is, fields where all the values are blank. Here is my python code. fn = "tmp1.csv" fin = open(fn, 'rb') rdr = csv.DictReader(fin, delimiter=',') data = list(