%pylab inline import pandas as pd pd.version.version np.version.version pd.set_option("max_rows", 100) pd.set_option("max_columns", 25) np.set_printoptions(linewidth=200) figsize(12,9) from IPython.display import HTML HTML('') #!curl -O http://dl.dropbox.com/u/90393/botliga/ergebnisse-1963-2010.zip #!unzip -qq ergebnisse-*.zip #cd tippkick/ #!psql -q < tippkick.sql import psycopg2 conn = psycopg2.connect("dbname=tippkick") import pandas.io.sql as psql vereine = psql.frame_query('select * from vereine', con=conn) vereine.head() spiele = psql.frame_query('select * from spiele', con=conn) spiele.head() temp = pd.merge(spiele, vereine, left_on="heim", right_on="id") temp.head() temp2 = pd.merge(temp, vereine, left_on="gast", right_on="id") temp2.head() df = temp2["name_y name_x saison tore_heim tore_gast spieltag zeit".split()] df.columns = "heim gast saison tore_heim tore_gast spieltag zeit".split() df df.set_index("zeit") df["tore"] = df["tore_heim"] + df["tore_gast"] saison_spieltag = df.set_index(["saison", "spieltag"]) print saison_spieltag.head().to_string() grouped = saison_spieltag["tore"].groupby(level=0) grouped.sum().plot(kind="bar") df[df["tore"] > 10].sort("tore", ascending=False) from IPython.display import YouTubeVideo YouTubeVideo('VfvWX4bHSb0') df.ix[2558] df.ix[0]["zeit"].hour df["uhrzeit"]=df["zeit"].apply(lambda x: str(x).split()[1]) startzeiten = df["uhrzeit"].value_counts() startzeiten startzeiten.plot(kind="barh") df[df["uhrzeit"] == "19:30:00"].sort("saison", ascending=False).head(10)