Q:

Counter according to other data and a range

The problem here's that I need a function to calculate the number of people who likes certain consoles, according to their civil status, gender, and a list of their ages (thought range() could work). Already made the code using pandas, but somehow i couldn't find any command that could help me.
        CustomerNo  Name LastName  Age CivilState Gender FavouriteConsole
0           1        Joe     Smith   48          M      M                W
1           2   Jonathan      Cage   20          S      M                X
2           3       Lucy     Chang   26          S      F                P
99         100  Alexander   Levine   41          M      M                X

For Favourite console W stands for wii, P for Ps3 and x for xbox.
What i need is something like this... 
For Wii there are x people, which x2 is male and x3 female, x3 are married and x4 are single, the range onf ages is [x5 to x6]

for each one of the consoles...

A:

Below is general function and not related to Panda.
Suppose you have data in some file say a.txt.
Below code scans file and prints output as mentioned in question,
#!/usr/bin/python

import sys
import os

def calc(console_name):
        f = open("a.txt")

        lines = f.readlines()[1:]
        # skipped first line

        num_people = 0
        num_males = 0
        num_females = 0
        num_married = 0
        num_unmarried = 0
        min_age = 0
        max_age = 0

        for line in lines:
                fields = line.split()

                if (fields[-1] == console_name):
                        num_people += 1

                        # Age
                        age = int(fields[4])
                        if min_age == 0:
                                min_age = age
                        else:
                                if age < min_age:
                                        min_age = age

                        if max_age == 0:
                                max_age = age
                        else:
                                if age >= max_age:
                                        max_age = age

                        # civil status
                        if fields[5] == 'M':
                                num_married += 1
                        elif fields[5] == 'S':
                                num_unmarried += 1

                        # Gender
                        if fields[6] == 'M':
                                num_males += 1
                        else:
                                num_females += 1

        print "For %s there are %s people, which %s are male and %s female, \
                %s are married and %s are unmarried, age range [ %s - %s]" % (console_name, num_people, num_males, num_females, num_married, num_unmarried, min_age, max_age)

c = 'W'
calc(c)

calc is function which does actual work. I have tested it for W field.
   Elite-MT-PC:~/Documents/programs$ python a.py 
    For W there are 1 people, which 1 are male and 0 female, 1 are married and 0 are unmarried, age range [ 48 - 48]

