Saturday, February 20
In SQL* you say
select sum(sales) from accounts where state="NY". In Pita, the way to do this is:
which will calculate for you the count, length, sum, minimum and maximum, as appropriate, for all the fields in the table at once, so the value you need is
results = accounts.aggregate(state='NY')**
results.sales.sum. Since the table scan is typically slower than any calculations you're likely to be doing, this seems a reasonable approach.
In addition, I've added a
which provides all those, plus mean,*** median, mode, standard deviation, and geometric and harmonic means. Aaaaand standard error, coefficient of variation, sample and population variance, skewness and kurtosis. I even sort of know what kurtosis is.
results = accounts.stats()
I'm working on two more functions now,
break, though I may need to come up with another name for the latter because break is a Python keyword. This:
would give you the aggregate sales figures for each state in the US, sensibly enough. And this:
for result in accounts.group('state', country='US'): ...
would give you the individual sales figures, and then automatically provide totals after the last sales record for each state.
for result in accounts.break('state', country='US'): ...
As long as I don't come down with kurtosis...
Update: Kang and jag. Or rather, agg and tab. For aggregate and tabulate.
will give you one summary line for each state, where
for line in accounts.aggregate('state', country='US'): ...
would give you both detail and summary lines. I need to put subtotal and total flags on the records for tabulate. Have to watch the keywords, there. And keep my closet doors closed.
for line in accounts.tabulate('state', country='US'): ...
* Boo, hiss!
** Or indeed
accounts(state='NY').aggregate()Either way should perform the same and produce the same results. I think...
*** Which should come out the same as the average; just one I'm calculating myself and the other I'm pulling out of a stats module.
OT: Pixy, I don't know what they did, but I can't load the Jawas now without locking up IE8. (Firefox has no problem with it.)
Posted by: Steven Den Beste at Saturday, February 20 2010 10:56 AM (+rSRq)
As I look at it with Firefox, I see that there's a formatting problem with the post titled "NYT: Brooklyn Accent = RAAAACIST!"
That may be related.
Posted by: Steven Den Beste at Saturday, February 20 2010 11:00 AM (+rSRq)
52 queries taking 0.1439 seconds, 283 records returned.
Powered by Minx 1.1.6c-pink.