import pandas as pd

# TODO: Load up the table, and extract the dataset
# out of it. If you're having issues with this, look
# carefully at the sample code provided in the reading
df = pd.read_html('http://www.espn.com/nhl/statistics/player/_/stat/points/sort/points/year/2015/seasontype/2')[0]

# TODO: Rename the columns so that they match the
# column definitions provided to you on the website
df.columns = df.ix[1, :]
df = df.ix[2:, :]

# TODO: Get rid of any row that has at least 4 NANs in it
df = df.dropna(thresh=4, axis=0).reset_index(drop=True)

# TODO: At this point, look through your dataset by printing
# it. There probably still are some erroneous rows in there.
# What indexing command(s) can you use to select all rows
# EXCEPT those rows?
df = df[df['RK'] != 'RK']

# TODO: Get rid of the 'RK' column
df = df.drop(labels=['RK'], axis=1)

# TODO: Ensure there are no holes in your index by resetting
# it. By the way, don't store the original index
df.reset_index(drop=True)

# TODO: Check the data type of all columns, and ensure those
# that should be numeric are numeric
df = df.apply(lambda x: pd.to_numeric(x, errors='ignore'))

# TODO: Your dataframe is now ready! Use the appropriate 
# commands to answer the questions on the course lab page.
print(df.shape)
print(len(df.PCT.unique()))
print(df.ix[16, 'GP'] + df.ix[17, 'GP'])
