Re: Pivot Table/Groupby/Sum question

2008-01-04 Thread petr . jakes . tpc
On Jan 4, 4:55 pm, [EMAIL PROTECTED] wrote: > Petr thanks so much for your input. I'll try to learnSQL, especially > if I'll do a lot of database work. > > I tried to do it John's way as en exercise and I'm happy to say I > understand a lot more. Basically I didn't realize I could nest > dictiona

Re: Pivot Table/Groupby/Sum question

2008-01-04 Thread patrick . waldo
Petr thanks so much for your input. I'll try to learn SQL, especially if I'll do a lot of database work. I tried to do it John's way as en exercise and I'm happy to say I understand a lot more. Basically I didn't realize I could nest dictionaries like db = {country:{genre:{sub_genre:3}}} and cal

Re: Pivot Table/Groupby/Sum question

2008-01-03 Thread petr . jakes . tpc
On Jan 3, 3:41 pm, [EMAIL PROTECTED] wrote: > Yes in the sense that the top part will have merged cells so that > Horror and Classics don't need to be repeated every time, but the > headers aren't the important part. At this point I'm more interested > in organizing the data itself and i can worry

Re: Pivot Table/Groupby/Sum question

2008-01-03 Thread patrick . waldo
Yes in the sense that the top part will have merged cells so that Horror and Classics don't need to be repeated every time, but the headers aren't the important part. At this point I'm more interested in organizing the data itself and i can worry about putting it into a new excel file later. -- h

Re: Pivot Table/Groupby/Sum question

2008-01-02 Thread petr . jakes . tpc
> So the data comes in as a long list. I'm dealing with some > information on various countries with 6 pieces of information to > pivot. Just to make it simple it's like a video store database. The > data is like [Country, Category, Sub Category, Film Title, Director, > Number of Copies]. data

Re: Pivot Table/Groupby/Sum question

2008-01-02 Thread patrick . waldo
Sorry for the delay in my response. New Year's Eve and moving apartment > - Where the data come from (I mean: are your data in Excel already > when you get them)? > - If your primary source of data is the Excel file, how do you read > data from the Excel file to Python (I mean did you solve this

Re: Pivot Table/Groupby/Sum question

2007-12-29 Thread petr . jakes . tpc
> Yes, I realize Excel has excellent support for pivot tables. However, > I hate how Excel does it and, for my particular excel files, I need > them to be formated in an automated way because I will have a number > of them over time and I'd prefer just to have python do it in a flash > than to do

Re: Pivot Table/Groupby/Sum question

2007-12-29 Thread patrick . waldo
On Dec 29, 3:00 pm, [EMAIL PROTECTED] wrote: > Patrick, > > in your first posting you are writing "... I'm trying to learn how to > make pivot tables from some excel sheets...". Can you be more specific > please? AFIK Excel offers very good support for pivot tables. So why > to read tabular data fr

Re: Pivot Table/Groupby/Sum question

2007-12-29 Thread petr . jakes . tpc
Patrick, in your first posting you are writing "... I'm trying to learn how to make pivot tables from some excel sheets...". Can you be more specific please? AFIK Excel offers very good support for pivot tables. So why to read tabular data from the Excel sheet and than transform it to pivot tabel

Re: Pivot Table/Groupby/Sum question

2007-12-29 Thread John Machin
On Dec 29, 11:51 am, [EMAIL PROTECTED] wrote: > John would you mind walking me through your class in normal speak? Yes. > I > only have a vague idea of why it works and this would help me a lot to > get a grip on classes and this sort of particular problem. It's about time you got a *concrete*

Re: Pivot Table/Groupby/Sum question

2007-12-28 Thread patrick . waldo
Petr, thanks for the SQL suggestion, but I'm having enough trouble in Python. John would you mind walking me through your class in normal speak? I only have a vague idea of why it works and this would help me a lot to get a grip on classes and this sort of particular problem. The next step is to

Re: Pivot Table/Groupby/Sum question

2007-12-28 Thread John Machin
On Dec 29, 9:58 am, [EMAIL PROTECTED] wrote: > What about to let SQL to work for you. The OP is "trying to learn how to make pivot tables from some excel sheets". You had better give him a clue on how to use ODBC on an "excel sheet" :-) [snip] > SELECT > NAME, > sum (AMOUNT) as TOTAL, > sum (case

Re: Pivot Table/Groupby/Sum question

2007-12-28 Thread petr . jakes . tpc
What about to let SQL to work for you. HTH Petr Jakes Tested on Python 2.5.1 8<-- #!/usr/bin/env python # -*- coding: utf-8 -*- import sqlite3 con = sqlite3.connect(":memory:") cur = con.cursor() inputData=( ('Bob', 'Morn', 240), ('Bob', 'Aft', 300), ('Joe', 'Morn', 70), ('

Re: Pivot Table/Groupby/Sum question

2007-12-28 Thread patrick . waldo
Wow, I did not realize it would be this complicated! I'm fairly new to Python and somehow I thought I could find a simpler solution. I'll have to mull over this to fully understand how it works for a bit. Thanks a lot! On Dec 28, 4:03 am, John Machin <[EMAIL PROTECTED]> wrote: > On Dec 28, 11:4

Re: Pivot Table/Groupby/Sum question

2007-12-27 Thread John Machin
On Dec 28, 11:48 am, John Machin <[EMAIL PROTECTED]> wrote: > On Dec 28, 10:05 am, [EMAIL PROTECTED] wrote: > > > > If you have any ideas about how to solve this pivot table issue, which > > seems to be scant on Google, I'd much appreciate it. I know I can do > > this in Excel easily with the auto

Re: Pivot Table/Groupby/Sum question

2007-12-27 Thread John Machin
On Dec 28, 10:05 am, [EMAIL PROTECTED] wrote: > On Dec 27, 10:59 pm, John Machin <[EMAIL PROTECTED]> wrote: > > > On Dec 28, 4:56 am, [EMAIL PROTECTED] wrote: > > > > from itertools import groupby > > > You seem to have overlooked this important sentence in the > > documentation: "Generally, the it

Re: Pivot Table/Groupby/Sum question

2007-12-27 Thread patrick . waldo
On Dec 27, 10:59 pm, John Machin <[EMAIL PROTECTED]> wrote: > On Dec 28, 4:56 am, [EMAIL PROTECTED] wrote: > > > from itertools import groupby > > You seem to have overlooked this important sentence in the > documentation: "Generally, the iterable needs to already be sorted on > the same key functi

Re: Pivot Table/Groupby/Sum question

2007-12-27 Thread John Machin
On Dec 28, 4:56 am, [EMAIL PROTECTED] wrote: > from itertools import groupby You seem to have overlooked this important sentence in the documentation: "Generally, the iterable needs to already be sorted on the same key function" -- http://mail.python.org/mailman/listinfo/python-list

Pivot Table/Groupby/Sum question

2007-12-27 Thread patrick . waldo
Hi all, I tried reading http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/334695 on the same subject, but it didn't work for me. I'm trying to learn how to make pivot tables from some excel sheets and I am trying to abstract this into a simple sort of example. Essentially I want to take in