Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #39339
| Newsgroups | comp.lang.python |
|---|---|
| Date | 2013-02-20 02:47 -0800 |
| References | <51240f54$0$40361$4fafbaef@reader1.news.tin.it> <kg1s92$5df$1@dont-email.me> <51248722$0$40358$4fafbaef@reader1.news.tin.it> |
| Message-ID | <5b5f7750-f87f-4bfc-8edc-26463b391173@googlegroups.com> (permalink) |
| Subject | Re: Import Json web data source to xls or csv |
| From | pyplexed <julius.welby@gmail.com> |
Try something like:
for d in data:
if d["bid"] is not None and d["ask"] is not None:
c.writerow([str(d["currency"]),str(d["symbol"]),str(d["bid"]),str(d["ask"]),str(d["currency_volume"])])
I've used 'is not None' in case 0 or 0.0 are acceptable bid or offer values. If you want to exclude rows with these values as well as None, you can just use:
for d in data:
if d["bid"] and d["ask"]:
# Do stuff
There are other ways to do this kind of thing, by the way. Check out list comprehensions sometime.
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Import Json web data source to xls or csv io <maroso@libero.it> - 2013-02-19 23:48 +0000
Re: Import Json web data source to xls or csv Michael Herman <hermanmu@gmail.com> - 2013-02-19 17:54 -0800
Re: Import Json web data source to xls or csv io <maroso@libero.it> - 2013-02-20 07:13 +0000
Re: Import Json web data source to xls or csv Michael Herman <hermanmu@gmail.com> - 2013-02-20 10:27 -0800
Re: Import Json web data source to xls or csv rusi <rustompmody@gmail.com> - 2013-02-20 23:29 -0800
Re: Import Json web data source to xls or csv Peter Otten <__peter__@web.de> - 2013-02-21 09:36 +0100
Re: Import Json web data source to xls or csv Cousin Stanley <cousinstanley@gmail.com> - 2013-02-20 06:59 +0000
Re: Import Json web data source to xls or csv io <maroso@libero.it> - 2013-02-20 08:19 +0000
Re: Import Json web data source to xls or csv pyplexed <julius.welby@gmail.com> - 2013-02-20 02:47 -0800
Re: Import Json web data source to xls or csv io <maroso@libero.it> - 2013-02-21 00:27 +0000
csiph-web