oseymour / ScraperFC

Python package for scraping soccer data from a variety of sources
GNU General Public License v3.0
222 stars 49 forks source link

Return pandas dataframe from Understat().scrape_shot_xy() #21

Closed matiast1905 closed 1 year ago

matiast1905 commented 1 year ago

Hi Owen, This is a really good package, works like a charm. I think it would be a nice feature to include an argument on this method to return a pandas dataframe instead of the current nested dictionaries.

oseymour commented 1 year ago

Hey @matiast1905! Thanks for the recommendation. I've added it to my project to-do list.

In the meantime, you can try pd.json_normalize() and pass the output of scrape_shot_xy(). It should be able to convert the dicts to a dataframe. You might have to reformat the dicts a bit.

oseymour commented 1 year ago

@matiast1905 this feature was added with the most recent commits and v2.6.4 on PyPI. The function now has a format argument. The default is "json" which doesn't change how the function operates. But if you set format to "dataframe" the function will return a Pandas DataFrame. Alternatively, if you paa save=True and format="dataframe" the output will be saved to a CSV, versus a JSON file if the format is "json".

matiast1905 commented 1 year ago

@oseymour I've tested it from PyPI and It works perfect, thank you!

oseymour commented 1 year ago

I'm glad it works like you want! Let me know if you need anything else!