Read Table with Show More Button using Pandas

share link

by Abdul Rawoof A R dot icon Updated: Feb 28, 2023

technology logo
technology logo

Solution Kit Solution Kit  

In Pandas, we are having one of the most used packages for analyzing data, data exploration, and manipulation. We often use the URLs to perform different operations while analyzing real-world data and pandas provides multiple methods to do so and one of those methods is the read_table() method.


  • Pandas: it is a Python library for data analysis and is built on top of two core Python libraries that are matplotlib used for data visualization and NumPy used for mathematical operations in Python. It acts as a wrapper over these libraries and allows us to access many of matplotlib's and NumPy's methods with less code. Pandas .plot() combines multiple matplotlib methods into a single method that enables us to plot a chat in a few lines.
  • Requests: it is a popular open-source HTTP library that simplifies working with HTTP requests, it is standard for making HTTP requests in Python and it abstracts the complexities of making requests behind a beautiful and simple API so that we can focus on interacting with services and consuming data in our application.


Here is an example of how to read a table with show more button using Pandas:

Fig : Preview of the output that you will get on running this code from your IDE.

Code

In this solution we're using Pandas and Requests libraries.

import pandas as pd
import requests

url = 'https://mobile-statsv2.sportsnet.ca/web_player_table?league=nhl&season=2021&season_type=reg'
jsonData = requests.get(url).json()
data = jsonData['data']

skaters_players_list_unclean = pd.json_normalize(data, 
                                         record_path=['player_stats', 'skaters'])

goalies_players_list_unclean = pd.json_normalize(data, 
                                         record_path=['player_stats', 'goalies'])

print(skaters_players_list_unclean)
     player_id player_name_formatted  ... last_name position
0      1214439           Ahcan, Jack  ...     Ahcan        D
1       230685     Bergeron, Patrice  ...  Bergeron        C
2       745313          Blidh, Anton  ...     Blidh       LW
3       878156        Carlo, Brandon  ...     Carlo        D
4       744943       Clifton, Connor  ...   Clifton        D
..         ...                   ...  ...       ...      ...
944     550771        Sheahan, Riley  ...   Sheahan       LW
945     744948         Soucy, Carson  ...     Soucy        D
946     913797        Tanev, Brandon  ...     Tanev       RW
947    1078266       True, Alexander  ...      True        C
948     741444        Wennberg, Alex  ...  Wennberg        C

[949 rows x 24 columns]


print(goalies_players_list_unclean)
     player_id player_name_formatted  ... last_name position
0       300802          Rask, Tuukka  ...      Rask        G
1      1057221       Swayman, Jeremy  ...   Swayman        G
2       681544        Ullmark, Linus  ...   Ullmark        G
3       176834       Anderson, Craig  ...  Anderson        G
4       826521           Dell, Aaron  ...      Dell        G
..         ...                   ...  ...       ...      ...
104     521575         Lehner, Robin  ...    Lehner        G
105    1139760       Thompson, Logan  ...  Thompson        G
106     878403         Daccord, Joey  ...   Daccord        G
107     680662       Driedger, Chris  ...  Driedger        G
108     555124     Grubauer, Philipp  ...  Grubauer        G

[109 rows x 25 columns]

import pandas as pd
import requests

url = 'https://site.web.api.espn.com/apis/common/v3/sports/hockey/nhl/statistics/byathlete'
payload = {
'region': 'us',
'lang': 'en',
'contentorigin': 'espn',
'isqualified': 'false',
'page': '1',
'limit': '999',
'sort': 'offensive:points:desc',
'category': 'skaters'}
jsonData = requests.get(url, params=payload).json()
data = jsonData['athletes']

players_list_unclean = pd.json_normalize(data)

print(players_list_unclean)
                                            categories  ... athlete.teamUId
0    [{'name': 'general', 'displayName': 'Own Gener...  ...   s:70~l:90~t:6
1    [{'name': 'general', 'displayName': 'Own Gener...  ...  s:70~l:90~t:26
2    [{'name': 'general', 'displayName': 'Own Gener...  ...   s:70~l:90~t:6
3    [{'name': 'general', 'displayName': 'Own Gener...  ...  s:70~l:90~t:21
4    [{'name': 'general', 'displayName': 'Own Gener...  ...  s:70~l:90~t:17
..                                                 ...  ...             ...
944  [{'name': 'general', 'displayName': 'Own Gener...  ...  s:70~l:90~t:26
945  [{'name': 'general', 'displayName': 'Own Gener...  ...  s:70~l:90~t:21
946  [{'name': 'general', 'displayName': 'Own Gener...  ...   s:70~l:90~t:1
947  [{'name': 'general', 'displayName': 'Own Gener...  ...  s:70~l:90~t:25
948  [{'name': 'general', 'displayName': 'Own Gener...  ...  s:70~l:90~t:24

[949 rows x 31 columns]

Instructions

Follow the steps carefully to get the output easily.

  1. Install pandas on your IDE(Any of your favorite IDE).
  2. Copy the snippet using the 'copy' and paste it in your IDE.
  3. Add required dependencies and import them in Python file.
  4. Run the file to generate the output.


I hope you found this useful. I have added the link to dependent libraries, version information in the following sections.


I found this code snippet by searching for 'how to read table with show more button using pandas' in kandi. You can try any such use case!

Environment Tested

I tested this solution in the following versions. Be mindful of changes when working with other versions.

  1. The solution is created in PyCharm 2021.3.
  2. The solution is tested on Python 3.9.7.
  3. Pandas version-v1.5.2.
  4. Requests version-v2.28.1.


Using this solution, we are able to read table with show more button using pandas with simple steps. This process also facilities an easy way to use, hassle-free method to create a hands-on working version of code which would help us to read table with show more button using pandas.

Dependent Libraries

pandasby pandas-dev

Python doticonstar image 38689 doticonVersion:v2.0.2doticon
License: Permissive (BSD-3-Clause)

Flexible and powerful data analysis / manipulation library for Python, providing labeled data structures similar to R data.frame objects, statistical functions, and much more

Support
    Quality
      Security
        License
          Reuse

            pandasby pandas-dev

            Python doticon star image 38689 doticonVersion:v2.0.2doticon License: Permissive (BSD-3-Clause)

            Flexible and powerful data analysis / manipulation library for Python, providing labeled data structures similar to R data.frame objects, statistical functions, and much more
            Support
              Quality
                Security
                  License
                    Reuse

                      requestsby psf

                      Python doticonstar image 49787 doticonVersion:v2.31.0doticon
                      License: Permissive (Apache-2.0)

                      A simple, yet elegant, HTTP library.

                      Support
                        Quality
                          Security
                            License
                              Reuse

                                requestsby psf

                                Python doticon star image 49787 doticonVersion:v2.31.0doticon License: Permissive (Apache-2.0)

                                A simple, yet elegant, HTTP library.
                                Support
                                  Quality
                                    Security
                                      License
                                        Reuse

                                          You can also search for any dependent libraries on kandi like 'pandas' and 'requests'.

                                          Support

                                          1. For any support on kandi solution kits, please use the chat
                                          2. For further learning resources, visit the Open Weaver Community learning page.


                                          See similar Kits and Libraries