コード例 #1
0
def test_howManyMedals():
    loader = FileLoader()
    data = loader.load('../data/athlete_events.csv')

    assert howManyMedals(data, 'Kjetil Andr Aamodt') == dict({
        1992: {
            'G': 1,
            'S': 0,
            'B': 1
        },
        1994: {
            'G': 0,
            'S': 2,
            'B': 1
        },
        1998: {
            'G': 0,
            'S': 0,
            'B': 0
        },
        2002: {
            'G': 2,
            'S': 0,
            'B': 0
        },
        2006: {
            'G': 1,
            'S': 0,
            'B': 0
        }
    })
コード例 #2
0
def test_SpatioTemporalData():
    loader = FileLoader()
    data = loader.load('../data/athlete_events.csv')
    sp = SpatioTemporalData(data)
    assert sp.where(1896) == ['Athina']
    assert sp.where(2016) == ['Rio de Janeiro']
    assert sp.when('Athina') == [2004, 1906, 1896]
    assert sp.when('Paris') == [1900, 1924]
コード例 #3
0
def test_proportionBySport():
    loader = FileLoader()
    data = loader.load('../data/athlete_events.csv')
    assert 0.01935634328358209 == proportionBySport(data, 2004, 'Tennis', 'F')
コード例 #4
0
# python -m ex05.HowManyMedalsByCountry
import pandas as pd
from ex00.FileLoader import FileLoader


def howManyMedalsByCountry(df, team):
    team_data = df.loc[df['Team'] == team].drop_duplicates(
        subset=["Year", "Event", "Medal"])

    medals = {}
    for year in team_data["Year"].unique():
        year_count = team_data.loc[team_data["Year"] ==
                                   year]["Medal"].value_counts()

        medals[year] = {
            "G": year_count["Gold"] if "Gold" in year_count else 0,
            "S": year_count["Silver"] if "Silver" in year_count else 0,
            "B": year_count["Bronze"] if "Bronze" in year_count else 0
        }

    return medals


if __name__ == "__main__":
    data = FileLoader().load("./data/athlete_events.csv")

    res = howManyMedalsByCountry(data, "France")

    for year in sorted(res.keys()):
        print(f"{year} -> {res[year]}")
コード例 #5
0
            'S': 0,
            'B': 1
        },
        1994: {
            'G': 0,
            'S': 2,
            'B': 1
        },
        1998: {
            'G': 0,
            'S': 0,
            'B': 0
        },
        2002: {
            'G': 2,
            'S': 0,
            'B': 0
        },
        2006: {
            'G': 1,
            'S': 0,
            'B': 0
        }
    })


if __name__ == "__main__":
    loader = FileLoader()
    data = loader.load('../data/athlete_events.csv')
    print(howManyMedals(data, 'Kjetil Andr Aamodt'))
コード例 #6
0
def test_youngestFellah():
    fl = FileLoader()
    data = fl.load('../data/athlete_events.csv')
    assert dict({'F': 13.0, 'M': 14.0}) == youngestFellah(data, 2004)