Skip to content
This repository has been archived by the owner on Nov 1, 2021. It is now read-only.

Trouble creating custom box score data frame #116

Open
WillPanarese opened this issue Mar 25, 2018 · 5 comments
Open

Trouble creating custom box score data frame #116

WillPanarese opened this issue Mar 25, 2018 · 5 comments

Comments

@WillPanarese
Copy link

I have been trying to play around with making a model using this API and have been attempting to create a large dataframe of team and player statistics for any given game. I can create a dataframe that takes all of the advanced statistics from a number of teams and put that into an excel, but when I try to get the advanced statistics for each player from each team, I get the following error:
TypeError: cannot concatenate object of type "<type 'instancemethod'>"; only pd.Series, pd.DataFrame, and pd.Panel (deprecated) objs are valid
let me know if anyone can help.

@rneu31
Copy link

rneu31 commented Mar 26, 2018

Can you share some example code?

@mneedham91
Copy link

Agree with @rneu31, please share your code @WillPanarese. Based on the error message this seems like an error in your use of pandas not a problem with nba_py, although I could be wrong!

@WillPanarese
Copy link
Author

Here is a sample of code below, I know it is messy and probably redundant, but I can create the first Data frame between the two teams, i get the error message on the second dataframe i try to make with player stats.

import pandas as pd
import numpy as np
from nba_py import team

teamIDs = ['1610612739', '1610612761']

df_team_stats = []
for id in teamIDs:
_team = team.TeamGeneralSplits(id, season='2017-18', measure_type='Advanced')
Monday_Games_Teams = _team.location()
df_team_stats.append(Monday_Games_Teams)

Monday_Games_Teams = pd.concat(df_team_stats)

CLE_team_stats = team.TeamGeneralSplits('1610612739', season='2017-18', measure_type='Advanced')
TOR_team_stats = team.TeamGeneralSplits('1610612761', season='2017-18', measure_type='Advanced')

CLE_stats = CLE_team_stats.location()

cols = list(CLE_stats.columns.values)

print(CLE_stats)

TOR_stats = TOR_team_stats.location()

CLEvsTOR_teams = pd.concat([CLE_stats, TOR_stats])

CLEvsTOR_teams.to_csv("CLEvsTOR_teams.csv")
print(CLEvsTOR_teams)

teamIDs = ['1610612739', '1610612761']

df_player_stats = []
for id in teamIDs:
_players = team.TeamPlayers(id, season='2017-18', measure_type='Advanced')
Monday_Games_Players = _players.season_totals
df_player_stats.append(Monday_Games_Players)

Monday_Games_Players = pd.concat(df_player_stats)

CLE_Players1 = team.TeamPlayers('1610612739', season='2017-18', measure_type='Advanced')
PHO_Players1 = team.TeamPlayers('1610612765', season='2017-18', measure_type='Advanced')

CLE_player_stats = CLE_Players1.season_totals

cols = list(CLE_player_stats.columns.values)

print(CLE_player_stats)

PHO_player_stats = PHO_Players1.season_totals

CLEvsPHO_players = pd.concat([CLE_player_stats, PHO_player_stats])

CLEvsPHO_players.to_csv('CLEvsPHO_players.csv')
print(CLEvsPHO_players)

@WillPanarese
Copy link
Author

my end goal is to try to create a custom box score in an excel spreadsheet like in this article http://blog.yhat.com/posts/visualize-nba-pipelines.html

the hope is that I can get all of the statistics I want, then start building an equation combing stats like OFF RTG DEF RTG, PIE, PER, VORP, etc. so I can compare teams playing and try to predict margin. I am just starting to play with this so bear with my mistakes, still learning.

@mneedham91
Copy link

Hi @WillPanarese, I'm not sure if the output is what you were looking for but I made some edits that get the script to run without an error message: https://pastebin.com/9mYcG9C1

I believe I added comments for each change I made.

I suspect there's a lot that could be done to improve your code beyond this but this should help you.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants