Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #97411
| Path | csiph.com!news.mixmin.net!proxad.net!feeder1-2.proxad.net!news.tele.dk!news.tele.dk!small.news.tele.dk!newsgate.cistron.nl!newsgate.news.xs4all.nl!nzpost1.xs4all.net!not-for-mail |
|---|---|
| Return-Path | <python-python-list@m.gmane.org> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.001 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'else:': 0.03; 'data:': 0.07; "'rb')": 0.09; 'csv': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'subject:CSV': 0.09; 'python': 0.10; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'row': 0.16; 'thanks.': 0.18; 'code.': 0.23; 'header:User- Agent:1': 0.26; 'header:X-Complaints-To:1': 0.26; 'this.': 0.28; 'values': 0.28; 'print': 0.30; 'code': 0.30; 'file': 0.34; 'there': 0.36; 'to:addr:python-list': 0.36; 'received:org': 0.37; 'data': 0.39; 'to:addr:python.org': 0.40; 'where': 0.40; 'hello,': 0.40; 'here': 0.66; 'received:116': 0.81; 'fin': 0.84 |
| X-Injected-Via-Gmane | http://gmane.org/ |
| To | python-list@python.org |
| From | Jaydip Chakrabarty <chalao.adda@gmail.com> |
| Subject | Finding Blank Columns in CSV |
| Date | Mon, 5 Oct 2015 13:29:03 +0000 (UTC) |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=UTF-8 |
| Content-Transfer-Encoding | 8bit |
| X-Gmane-NNTP-Posting-Host | 116.193.139.6 |
| User-Agent | Pan/0.139 (Sexual Chocolate; GIT bf56508 git://git.gnome.org/pan2) |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.20+ |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <https://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 | <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.389.1444052108.28679.python-list@python.org> (permalink) |
| Lines | 37 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1444052108 news.xs4all.nl 23826 [2001:888:2000:d::a6]:60325 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:97411 |
Show key headers only | View raw
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(rdr)
flds = rdr.fieldnames
fin.close()
mt = []
flag = 0
for i in range(len(flds)):
for row in data:
if len(row[flds[i]]):
flag = 0
break
else:
flag = 1
if flag:
mt.append(flds[i])
flag = 0
print mt
I need to know if there is better way to code this.
Thanks.
Back to comp.lang.python | Previous | Next — Next in thread | Find similar | Unroll thread
Finding Blank Columns in CSV Jaydip Chakrabarty <chalao.adda@gmail.com> - 2015-10-05 13:29 +0000 Re: Finding Blank Columns in CSV Denis McMahon <denismfmcmahon@gmail.com> - 2015-10-05 20:56 +0000
csiph-web