Exemplo n.º 1
0
def get_age(stats_df, people_df=None):
    if people_df is None:
        people_df = people()
    return (stats_df.merge(
        people_df.filter(["playerID", "birthYear"], axis=1),
        on="playerID").assign(age=lambda row: (row.yearID - row.birthYear).
                              astype(NULLABLE_INT)).filter(
                                  ["playerID", "yearID", "age"], axis=1))
Exemplo n.º 2
0
def get_age(stats_df: pd.DataFrame,
            people_df: pd.DataFrame = None) -> pd.DataFrame:
    if people_df is None:
        people_df = people()
    return (stats_df.merge(
        people_df.filter(["playerID", "birthYear"], axis=1),
        on="playerID").assign(age=lambda row: (row.yearID - row.birthYear).
                              astype(pd.Int32Dtype())).filter(
                                  ["playerID", "yearID", "age"], axis=1))
Exemplo n.º 3
0
    def __init__(self,
                 stats_df: pd.DataFrame = None,
                 primary_pos_df: pd.DataFrame = None):

        self.stats_df = stats_df if stats_df is not None else self._load_data()
        self.validate_data(self.stats_df)
        self.stats_df = self.preprocess_data(self.stats_df)

        self.primary_pos_df = (get_primary_position(fielding())
                               if primary_pos_df is None else primary_pos_df)
        self.metric_weights = np.array(self.METRIC_WEIGHTS)
        self.pt_weights = np.array(self.PT_WEIGHTS)
        self.league_avg_pa = self.LEAGUE_AVG_PT
        self.people = people()
Exemplo n.º 4
0
import seaborn as sns

pd.set_option('display.max_columns', None)
#remove chained assignment
#you can read more about chained assignment here: https://pandas.pydata.org/pandas-docs/version/0.22.0/indexing.html
pd.set_option('chained_assignment', None)

#setting these for later use
OAK_PRIMARY_COLOR = '#003831'
OAK_SECONDARY_COLOR = '#EFB21E'
STL_PRIMARY_COLOR = '#FF0000'
STL_SECONDARY_COLOR = '#0000FF'

# each of these functions gets us back a DataFrame.
salaries = la.salaries()
names = la.people()
teams = la.teams()
batting = la.batting()
home_games = la.home_games()

plt.style.use('seaborn-whitegrid')

salaries_teams_years = salaries.groupby(['teamID', 'yearID'],
                                        as_index=False).sum()

oak = salaries_teams_years.loc[salaries_teams_years['teamID'] == 'OAK']
stl = salaries_teams_years.loc[salaries_teams_years['teamID'] == 'SLN']

fig, ax = plt.subplots(figsize=(10, 7))

ax.plot(stl['yearID'],