A scraper that directly gives football(not soccer) data from FBRef website directly to Pandas dataframe. Major teams and leagues supported.
Project description
FBREF2PANDAS - Export FBRef data to Pandas Dataframe
A scraper that directly gives football(not soccer) data from FBRef website directly to Pandas dataframe. Major teams and leagues supported.
Contribute to the Project so that everyone can benefit from it.
Disclaimer : This package in no way tries to take away from the work of FBRef.com I love that website and just needed a package that makes my life easier
To install the package(it just requires pandas
!!) :
pip install fbref2pandas
After installation, create a MatchLogsLink
object by providing it the following arguments(in str
format) :
- team_id : The identifier of the team. Generally, as I have noticed, fbref uses a particular
id
for each of the team. It is a 8 character string that uniquely identifies a football team. See this table forid
of some popular teams.
Team ID | Team Name |
---|---|
'206d90db' | 'Barcelona' |
'53a2f082' | 'Real-Madrid' |
'db3b9613' | 'Atletico-Madrid' |
'e31d1cd9' | 'Real-Sociedad' |
'2a8183b3' | 'Villarreal' |
Just copy the team_id
and pass as the first argument.
-
year
: Theyear
for which the data is required. Theyear
is in the format2022-2023
(for 2022-23 season). Pass this as second argument in theMatchLogsLink
object. -
comp_id
: Thecomp_id
is also one of the variables that fbref maintains internally, as far as I can deduce. Thecomp_id
is of the formcXXX
, and can be found from the fbref website. See this table below for some commoncomp_id
Comp ID | Competition Name |
---|---|
'c8' | 'Champions-League' |
'c12' | 'La-Liga' |
'c19' | 'Europa-League' |
'c122' | 'UEFA-Super-Cup' |
'c569' | 'Copa-del-Rey' |
'c646' | 'Supercopa-de-Espana' |
'c882' | 'Europa-Conference-League' |
log_type
: I love how many stats are available in the fbref website. These are just awesome for your next project. Thelog_type
could be any of these values:
Log Type |
---|
'scores_and_fixtures' |
'shooting' |
'goalkeeping' |
'passing' |
'pass_types' |
'goal_and_shot_creation' |
'defensive_actions' |
'possession' |
'miscellaneous_stats' |
After passing these 4 parameters to the MatchLogsLink
object, most of the task is done. Just create a new Data
object, and pass the above MatchLogsLink
object. An example of this would be :
link = MatchLogsLink('206d90db', '2022-2023', 'c12', 'shooting')
# print(link)
data = Data(link)
If the link is correct, there shouldn't be a problem. Now, to get the data as a DataFrame
object, just call the function fbref2pandas()
of the Data
object. The functions returns the data as a pandas Dataframe
. If the link is incorrect, an exception is raised. Just double check if the data from the table above. Enjoy the data.
To get the data as DataFrame
:
df = data.fbref2pandas()
Note : I comply with all the rules given for the data use in the sports reference website, and I believe that it is in fair use. Not many requests will be taken from this package.
Note : Help would be really appreciated to expand this package. Create a PR and add whatever you could scrape from links of FBRef. Great PRs will be merged on small notices.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file fbref2pandas-0.0.1.tar.gz
.
File metadata
- Download URL: fbref2pandas-0.0.1.tar.gz
- Upload date:
- Size: 3.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 03b87c380bfc3ccd30b5b864b10ca1510e5a8bc71dde228b780cae558117b9a6 |
|
MD5 | c5599a1ce32e5495cc8d4244507b5a5e |
|
BLAKE2b-256 | 23633cf8bd6ddf3ca6f6b4b57ea8c33dc2f589fc906db4fc0b83b72a9daea51c |
File details
Details for the file fbref2pandas-0.0.1-py3-none-any.whl
.
File metadata
- Download URL: fbref2pandas-0.0.1-py3-none-any.whl
- Upload date:
- Size: 4.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9f9f23dffe271b244b2de8f4e834dc8c8d69209cc763ccf4c516be2603dc212a |
|
MD5 | d94f5cb1f4213fd897d5296026534dac |
|
BLAKE2b-256 | 17ab3f512c8c08ff5cbc485bb79a117309c8260ddff4fc34c7c6aba1d0d174bb |