Hi all,
Fairly new Python guy here. I am having a lot of trouble trying to
figure this out. I have some data on some regulations in Excel and I
need to basically add up the total regulations for each country--a
statistical analysis thing that I'll copy to another Excel file.
Writing with pyExcelerator has been easier than reading with xlrd for
me...So that's what I did first, but now I'd like to learn how to
crunch some data.
The input looks like this:
Country Module
Topic # of Docs
Argentina Food and Consumer Products Cosmetics 1
Argentina Food and Consumer Products Cosmetics 8
Argentina Food and Consumer Products Food Additives 1
Argentina Food and Consumer Products Food Additives 1
Australia Food and Consumer Products Drinking Water 7
Australia Food and Consumer Products Food Additives 3
Australia Food and Consumer Products Food Additives 1
etc...
So I need to add up all the docs for Argentina, Australia, etc...and
add up the total amount for each Topic for each country so, Argentina
has 9 Cosmetics laws and 2 Food Additives Laws, etc...
So, here is the reduced code that can't add anything...Any thoughts
would be really helpful.
import xlrd
import pyExcelerator
from pyExcelerator import *
#Open Excel files for reading and writing
path_file = "c:\\1\\data.xls"
book = xlrd.open_workbook(path_file)
Counts = book.sheet_by_index(1)
wb=pyExcelerator.Workbook()
matrix = wb.add_sheet("matrix")
#Get all Excel data
n=1
data = []
while n<Counts.nrows:
data.append(Counts.row_values(n, start_colx=0, end_colx=None))
n=n+1
COUNTRY, MODULE, TOPIC,DOCS = range(4)
COUNTRY_TOT = []
n=0
while n<len(data):
x=n
while data[n][COUNTRY]==data[n+1][COUNTRY]:
n=n+1
print sum(data[x:n][FT_DOCS])
wb.save('c:\\1\\matrix.xls') 2 1415
On Nov 29, 5:46 pm, patrick.wa...@gmail.com wrote:
Hi all,
Fairly new Python guy here. I am having a lot of trouble trying to
figure this out. I have some data on some regulations in Excel and I
need to basically add up the total regulations for each country--a
statistical analysis thing that I'll copy to another Excel file.
Writing with pyExcelerator has been easier than reading with xlrd for
me...So that's what I did first, but now I'd like to learn how to
crunch some data.
The input looks like this:
Country Module
Topic # of Docs
Argentina Food and Consumer Products Cosmetics 1
Argentina Food and Consumer Products Cosmetics 8
Argentina Food and Consumer Products Food Additives 1
Argentina Food and Consumer Products Food Additives 1
Australia Food and Consumer Products Drinking Water 7
Australia Food and Consumer Products Food Additives 3
Australia Food and Consumer Products Food Additives 1
etc...
So I need to add up all the docs for Argentina, Australia, etc...and
add up the total amount for each Topic for each country so, Argentina
has 9 Cosmetics laws and 2 Food Additives Laws, etc...
So, here is the reduced code that can't add anything...Any thoughts
would be really helpful.
import xlrd
import pyExcelerator
from pyExcelerator import *
#Open Excel files for reading and writing
path_file = "c:\\1\\data.xls"
book = xlrd.open_workbook(path_file)
Counts = book.sheet_by_index(1)
wb=pyExcelerator.Workbook()
matrix = wb.add_sheet("matrix")
#Get all Excel data
n=1
data = []
while n<Counts.nrows:
data.append(Counts.row_values(n, start_colx=0, end_colx=None))
n=n+1
COUNTRY, MODULE, TOPIC,DOCS = range(4)
COUNTRY_TOT = []
n=0
while n<len(data):
x=n
while data[n][COUNTRY]==data[n+1][COUNTRY]:
n=n+1
print sum(data[x:n][FT_DOCS])
wb.save('c:\\1\\matrix.xls')
Considering the topic of the usenet group, I know this is heresy but
I'd suggest using the Pivot Table feature in Excel. The whole thing
will be done if 5 clicks and no code. Simple is better than complex. ca******@gmail.com wrote:
On Nov 29, 5:46 pm, patrick.wa...@gmail.com wrote:
>Hi all,
Fairly new Python guy here. I am having a lot of trouble trying to figure this out. I have some data on some regulations in Excel and I need to basically add up the total regulations for each country--a statistical analysis thing that I'll copy to another Excel file. Writing with pyExcelerator has been easier than reading with xlrd for me...So that's what I did first, but now I'd like to learn how to crunch some data.
The input looks like this:
Country Module Topic # of Docs Argentina Food and Consumer Products Cosmetics 1 Argentina Food and Consumer Products Cosmetics 8 Argentina Food and Consumer Products Food Additives 1 Argentina Food and Consumer Products Food Additives 1 Australia Food and Consumer Products Drinking Water 7 Australia Food and Consumer Products Food Additives 3 Australia Food and Consumer Products Food Additives 1 etc...
So I need to add up all the docs for Argentina, Australia, etc...and add up the total amount for each Topic for each country so, Argentina has 9 Cosmetics laws and 2 Food Additives Laws, etc...
So, here is the reduced code that can't add anything...Any thoughts would be really helpful.
import xlrd import pyExcelerator from pyExcelerator import *
#Open Excel files for reading and writing path_file = "c:\\1\\data.xls" book = xlrd.open_workbook(path_file) Counts = book.sheet_by_index(1) wb=pyExcelerator.Workbook() matrix = wb.add_sheet("matrix")
#Get all Excel data n=1 data = [] while n<Counts.nrows: data.append(Counts.row_values(n, start_colx=0, end_colx=None)) n=n+1
COUNTRY, MODULE, TOPIC,DOCS = range(4) COUNTRY_TOT = [] n=0 while n<len(data): x=n while data[n][COUNTRY]==data[n+1][COUNTRY]: n=n+1 print sum(data[x:n][FT_DOCS])
wb.save('c:\\1\\matrix.xls')
Check itertools.groupby() and operator.itemgetter() This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: bobdedogh |
last post by:
can anyone add live hyperlinks to the sortable table made by the code
supplied by Machi, or know of a simple alternative
bob
Machi wrote Mar 10 1999, 8:00 am
>>>>>>>>>>>>>>
....
Hello...
|
by: Christopher |
last post by:
Hi...
I would be very grateful If You could resolve my question, my question is
"How do tabular a ListBox that their property DrawMode is OwnerDrawFixe?".
I do know as tabular a listbox, but I...
|
by: t |
last post by:
Hi,
I have the following problem. The web-based software I am to create is going
to display tabular data. Lots of data so I need some pagging mechanism. I
thought about creating three classes:...
|
by: lucky |
last post by:
Hi guys,
i want to write some data in tabular format in text file. i've data in
strings and i want to write like this in file
col1 col2 col3
d1 d1 d1
d2 d2 ...
|
by: maylee21 |
last post by:
hi, anyone can help me figure out how to read data from a text file
like this:
10980012907200228082002
and extract the data according to this kind of format:
Record type 1
TY-RECORD ...
|
by: Sanders Kaufman |
last post by:
I'm converting my table-based layouts to css-positioned divs - but the
ONLY reason I'm doing it is because it's *considered* a best practice.
I don't really see where anything goes hinky when...
|
by: Lars Eighner |
last post by:
Is a calendar tabular data, logically meriting table markup?
--
Lars Eighner <http://larseighner.com/ <http://myspace.com/larseighner>
Countdown: 465 days to go.
What do you do when...
|
by: scubak1w1 |
last post by:
Hello,
I am wanting a "pretty output" of tabular data generated on the fly and saved in an array (PHP)...
That is, I have a link so users can chart (JpGraph) and download (CSV) tabular data,...
|
by: LBLB |
last post by:
In terms of processing speed, what is the best method for displaying tabular data from a database in a Windows forms C# app? We generally use data grids (Infragistics WinGrid), but have an instance...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
| |