Python dictionary / database in memory
Question: I have a file that looks like this:

    
    
    LastName    FirstName   Age Gender  Height  Weight
    Smith   May 20  F   1500    55
    Wilder  Harry   25  M   1800    65
    Potter  Harry   50  M   1600    66
    Lincoln Abram   100 M   1800    55
    Reynolds    Mary    55  F   1600    55
    Anderson    Jane    40  F   1700    60
    Smith   William 42  M   1520    60
    

I want to be able to search in memory for example to find who has a height of
1800, or who has a last name of Smith, without having to read the file again.

I can read the file using import csv

    
    
    filename = r'C:\Users\wsteve46\Documents\Python\People.csv'
    reader = csv.DictReader(open(filename))
    
    results = []
    resdict = []
    
    for row in reader:
        try:
            print 'Row = ',row
            results.append(row.values())
            resdict.append(row)
    
        except:
             break
             print 'break ',row
    fieldnames = row.keys()
    

However, resdict is a list, not a dictionary. What is the best way to access
this data by key/value?


Answer: the easiest way for this is using `pandas`

    
    
    import pandas as pd
    data = pd.read_csv(fn)
    print data[data.Height == 1800]
    print data[data.LastName == 'Smith']
    

you'll have to do more research on your own, but that answers your first
question.

