473,655 Members | 3,112 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Yet Another Tabular Data Question

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.xl s"
book = xlrd.open_workb ook(path_file)
Counts = book.sheet_by_i ndex(1)
wb=pyExcelerato r.Workbook()
matrix = wb.add_sheet("m atrix")

#Get all Excel data
n=1
data = []
while n<Counts.nrows :
data.append(Cou nts.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')
Nov 29 '07 #1
2 1440
On Nov 29, 5:46 pm, patrick.wa...@g mail.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.xl s"
book = xlrd.open_workb ook(path_file)
Counts = book.sheet_by_i ndex(1)
wb=pyExcelerato r.Workbook()
matrix = wb.add_sheet("m atrix")

#Get all Excel data
n=1
data = []
while n<Counts.nrows :
data.append(Cou nts.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.
Nov 30 '07 #2
ca******@gmail. com wrote:
On Nov 29, 5:46 pm, patrick.wa...@g mail.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.xl s"
book = xlrd.open_workb ook(path_file)
Counts = book.sheet_by_i ndex(1)
wb=pyExcelerat or.Workbook()
matrix = wb.add_sheet("m atrix")

#Get all Excel data
n=1
data = []
while n<Counts.nrows :
data.append(Cou nts.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.group by() and operator.itemge tter()
Nov 30 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
2173
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 Harjinder!
1
2036
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 don't know is as tabular a listbox in the which its DrawMode Property is OwnerDrawFixed. I thank their help.
2
1318
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: GridView (displayng tabular data), PaggingControl (displaying and buttons) and DataSource (for retrieving data from the db. In the database I have following data: id | column1 | column2 -------------------------------------
3
2180
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 d2 d3 d3 d3
3
5713
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 PIC (1). ID-PARTICIPANT PIC (6).
38
3279
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 tables are used - but I'm doing it anyway because the HTML and CSS specs says to reserve tables for tabular data. So as I convert my login widgit to a css thing, I'm saying to myself - hey, this form is most certainly "tabular data" - even if it...
5
2299
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 you're debranded?
3
2217
scubak1w1
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, based on their selections on a query web page and using PHP, etc to pull the data out of a PostgreSQL database. I have been requested to make ('on the fly') a 'reporting quality' version of the CSV available for download - sort of like you might get...
1
2030
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 where run-time performance MUST be optimal - coding complexity and other things are less important. Here are some paticulars: 1. Data is stored in SQL Server. 2. Data is read-only. 3. The container/control must allow for mouse-click event handling...
0
8296
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8816
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8710
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8497
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8598
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7310
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6162
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4299
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2721
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.