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') 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. 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() 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 Harjinder!
|
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.
|
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
-------------------------------------
|
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
|
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).
| |
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...
|
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?
|
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...
|
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...
|
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,...
|
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...
| |
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...
|
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,...
|
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...
|
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...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
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
| |