0

I'm trying to automate pybaseball from player lookup to data extraction and can't seem to get past the first step of setting the player id as a variable.

I'm utilizing the following code to pull player id:

from pybaseball import playerid_lookup

data = playerid_lookup("kershaw", "clayton", fuzzy=True)

The output from the above lines are (exact copy/paste):

  name_last name_first  key_mlbam key_retro  key_bbref  key_fangraphs  mlb_played_first  mlb_played_last
0   kershaw    clayton     477132  kersc001  kershcl01           2036            2008.0           2022.0

Is there a method for setting the key_fangraphs number (2036) to a variable from this output?

1 Answer 1

1

As the pybaseball.playerid_lookup.playerid_lookup() method returns a pandas.DataFrame, you should be able to use the pandas.DataFrame.get() method. Something like data.get("key_fangraphs", default=-1). It would return -1 if there was no "key_fangraphs" column.

Sign up to request clarification or add additional context in comments.

1 Comment

That's what I was looking for, thanks! For anyone else that finds this I utilized .to_string(index=False) to remove the row index and output just the data.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.