Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #55727

Re: frequency of values in a field

Path csiph.com!eeepc.pasdenom.info!news.pasdenom.info!news.dougwise.org!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!weretis.net!feeder4.news.weretis.net!news.mixmin.net!news2.arglkargh.de!news.wiretrip.org!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <vlastimil.brom@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.012
X-Spam-Evidence '*H*': 0.98; '*S*': 0.00; 'python.': 0.05; 'variant': 0.07; 'python': 0.08; 'collections': 0.09; 'counting': 0.09; 'skip:[ 30': 0.09; '>>>': 0.11; 'places.': 0.16; 'writes:': 0.17; 'values': 0.18; 'header:In-Reply-To:1': 0.23; 'appropriate': 0.25; 'code': 0.25; 'handling': 0.25; '(in': 0.25; 'paul': 0.27; 'curious': 0.28; 'message-id:@mail.gmail.com': 0.29; 'decimal': 0.30; 'digits': 0.30; 'import': 0.31; 'to:addr:python-list': 0.31; 'actually': 0.31; 'ways': 0.34; 'print': 0.35; 'another': 0.35; 'using': 0.35; 'but': 0.36; 'table': 0.36; 'tool': 0.36; 'received:209.85': 0.38; 'received:google.com': 0.38; 'might': 0.38; 'skip:t 20': 0.38; 'actual': 0.39; 'subject:: ': 0.39; 'to:addr:python.org': 0.40; 'records': 0.65; 'atleast': 0.84; 'records:': 0.84; 'frequency': 0.93
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:in-reply-to:references:date :message-id:subject:from:to:content-type; bh=O33NDXZV69wp2yJdI0UfERRkt7LpAi1T4R/6+ExBQxs=; b=EOmvymVcd4DNH1n6NxOEs+iK5cpXmuKFcMaIuUkXCFkos/KUAER/s++ROj9gcjfDAI 2lxyRDd7jUx7OM1qOyatRuffEXYcuBCuwc9qgSVDm+C6Ja3X9ITMkQbqVCZBLul2ET0o XCYl5EBU1ySmwr1zYhoDqIF6yuUjZO2UIozUc=
DomainKey-Signature a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; b=RcDxM6/2qY2X8F5GOI8xS/q2VpOClRxYPfFSgQWUUcCSabuij9d6zK1tMgzUMcGjb+ GGyO7akWiQjMo5hRvDJ8lpgiZ9xwYuKPyElSjAeff3Afkj4WHmZ8KHB6XwzB3izDv4Jx 06NeUjnwCtM6OBVoXyeBb3ZzPF1WguMzFfcOI=
MIME-Version 1.0
In-Reply-To <7x7hdarzol.fsf@ruckus.brouhaha.com>
References <2f463773-da89-4c50-bd4f-8f891e6038a7@d12g2000vbz.googlegroups.com> <7x7hdarzol.fsf@ruckus.brouhaha.com>
Date Tue, 8 Feb 2011 23:25:43 +0100
Subject Re: frequency of values in a field
From Vlastimil Brom <vlastimil.brom@gmail.com>
To python-list@python.org
Content-Type text/plain; charset=ISO-8859-1
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://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 <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.21.1297203945.1633.python-list@python.org> (permalink)
Lines 37
NNTP-Posting-Host 82.94.164.166
X-Trace 1297203945 news.xs4all.nl 81482 [::ffff:82.94.164.166]:38230
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:55727

Show key headers only | View raw


2011/2/8, Paul Rubin <no.email@nospam.invalid>:
> noydb <jenn.duerr@gmail.com> writes:
>> I am looking for ways to go about capturing the frequency of unique
>> values in one field in a dbf table which contains ~50k records.  The
>> values are numbers with atleast 5 digits to the right of the decimal,
>> but I want the frequency of values to only 2 decimal places.  I do
>> have a method to do this courtesy of a provided tool in ArcGIS.  Was
>> just curious about ways to do it without arcgis sw, using just python.
>...
>
>     from decimal import Decimal as D
>     from collections import defaultdict
>
>     records = ['3.14159','2.71828','3.142857']
>
>     td = defaultdict(int)
>     for x in records:
>         td[D(x).quantize(D('0.01'))] += 1
>
>     print td
>
>>...

Another variant of the above code using collections.Counter (in newer
python versions);
The actual frequency counting code is actually the single
instantiation of the Counter  from an iterable. The appropriate
handling of the number values might be tweaked as needed.

>>> from decimal import Decimal as D
>>> from collections import Counter
>>> records = ['3.14159','2.71828','3.142857']
>>> Counter(D(x).quantize(D('0.01')) for x in records)
Counter({Decimal('3.14'): 2, Decimal('2.72'): 1})
>>>

vbr

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: frequency of values in a field Vlastimil Brom <vlastimil.brom@gmail.com> - 2011-02-08 23:25 +0100

csiph-web