Skip to content
Advertisement

Capture python output to variable

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:

JavaScript

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

JavaScript

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

Advertisement

Answer

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.

Advertisement