I figured out the answer myself and no longer need this post.
1 1153 bvdet 2,851
Recognized Expert Moderator Specialist
Ok, so lets say I have a .csv file called flags.csv, with the following data
(Column 1)- (Column 2)
Country- Colour
Australia- Red
Australia- Red
Australia- Red
America - Red
UK - Red
Japan- Red
China - Red
Australia- White
America - White
UK - White
Japan - White
Australia -Blue
America - Blue
UK - Blue
China - Yellow
I would like to arrange this data so as to present the countries with flags of at least three colours, and the total number of colours they have. I want the output to end up in this format.
Column1-Column2-Column3-Column4-Column5
--------- Blue - Red - White - Yellow - Total
America-- 1 - 3 - 1 - 0 - 5
Australia- 1 - 1 - 1 - 0 - 3
UK------- 1 - 1 - 1 - 0 - 3
I have no idea what the formulas for manipulating the data so as it forms in this way are. Could you please give me some help?
Thank you.
Compile the data into a dictionary. From there you can extract the data you need and convert to another format if needed. - data = """Country- Colour
-
Australia- Red
-
Australia- Red
-
Australia- Red
-
America - Red
-
UK - Red
-
Japan- Red
-
China - Red
-
Australia- White
-
America - White
-
UK - White
-
Japan - White
-
Australia -Blue
-
America - Blue
-
UK - Blue
-
China - Yellow"""
-
-
dataList = data.split("\n")[1:]
-
dd = {}
-
for item in dataList:
-
country, color = [s.strip() for s in item.split("-")]
-
dd.setdefault(country, []).append(color)
-
-
print
-
print " Country: Blue Red White Yellow Total"
-
-
for country in dd:
-
print "%10s:%5s%5s%5s%5s%5s" % (country,
-
dd[country].count("Blue"),
-
dd[country].count("Red"),
-
dd[country].count("White"),
-
dd[country].count("Yellow"),
-
len(dd[country]))
The output: - >>>
-
Country: Blue Red White Yellow Total
-
Japan: 0 1 1 0 2
-
Australia: 1 3 1 0 5
-
China: 0 1 0 1 2
-
America: 1 1 1 0 3
-
UK: 1 1 1 0 3
-
>>>
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: rh0dium |
last post by:
Hi all,
I believe I am having a fundamental problem with my class and I can't
seem to figure out what I am doing wrong. Basically I want a class
which can do several specific ldap queries. So in my code I would have
multiple searches. But I can't figure out how to do it without it
barfing..
The error is straightforward ..
|
by: Chris Uwins |
last post by:
Hi there, i know theres a number of ways I can achieve this but want
to know the best, (but still quite simple).
Up until a year ago I never used Access but have designed a few
databases for work. I am working on Access 2000.
I have basic SQL/VB skills - and am pretty accomplished at putting the
databases together.
Anyway...I've created a database to keep track of "Dayworks" we are
|
by: David Van D |
last post by:
Hi there,
A few weeks until I begin my journey towards a degree in Computer
Science at Canterbury University in New Zealand,
Anyway the course tutors are going to be teaching us JAVA wth bluej and
I was wondering if anyone here would be able to give me some tips for
young players such as myself, for learning the language.
Is this the best Newsgroup for support with JAVA?
|
by: nuffnough |
last post by:
This is python 2.4.3 on WinXP under PythonWin.
I have a config file with many blank lines and many other lines that I
don't need.
read the file in, splitlines to make a list, then run a loop that
looks like this:
|
by: tony |
last post by:
I'm using PHP 5 on Win-98 command line (ie no web server involved)
I'm processing a large csv file and when I loop through it I can process
around 275 records per second.
However at around 6,000 records this suddenly drops off to around 40
records per second.
This is a big problem as the "live" list is over 4 million records long.
I'd break it up but this is to be a regular test so that would be messy
| |
by: Bucco |
last post by:
I am trying to compare a list of items to the list of files generated
by os.listdir. I am having trouble getting this to work and think I
may be going down the wrong path. Please let me know if hter is a
better way to do this. THis is what I have for my class so far:
import os, sys
class MatchList:
def __init__(self, dir, file):
self.dir = os.listdir(dir)
|
by: John Salerno |
last post by:
Here's the code:
class MyFrame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, wx.ID_ANY)
panel = wx.Panel(self)
dbconn = self.connect_db()
dbconn.execute("select namefirst, namelast from master")
bb_players =
|
by: jon |
last post by:
Hi there,
I'm brand new to Access and may be trying to do too much too soon, but
I wanted to get some expert advice on how the best way to go about what
I am trying to accomplish would be.
I am trying to modify the Microsoft Template at the following address
(http://office.microsoft.com/en-us/templates/TC012186931033.aspx?CategoryID=CT101426031033)
to work as an issues tracker that imports and updates the issues from a
SQL 2005...
|
by: ARC |
last post by:
Hello all,
So I'm knee deep in this import utility program, and am coming up with all
sorts of "gotcha's!".
1st off. On a "Find Duplicates Query", does anyone have a good solution for
renaming the duplicate records? My thinking was to take the results of the
duplicate query, and somehow have it number each line where there is a
duplicate (tried a groups query, but "count" won't work), then do an update
query to change the duplicate to...
|
by: yueying53 |
last post by:
I am new to creating a list of classes. Hence I checked out this website: http://www.daniweb.com/code/snippet390.html. However, I modified the code to check if a class with a particular has been created before.
My code works when I create the first class and append it to the list. However, subsequent creations and appending results in this error: "AttributeError: No __call__ method defined." Why is this so? Why does the program from the...
|
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: 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: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
| |
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| | |