swar / nba_api

An API Client package to access the APIs for NBA.com
MIT License
2.49k stars 534 forks source link

How to identify the data set type in data_sets? #20

Closed whichen closed 5 years ago

whichen commented 5 years ago

test2 = scoreboardv2.ScoreboardV2(game_date='11/21/2018') data_sets = test2.data_sets for i in test2.data_sets: print(i.get_json( ))

How can I identify the type of every data set in easiest way? For example 'LastMeeting', 'LineScore', 'SeriesStandings' .

xeacott commented 5 years ago

Would type(obj) not be easiest inside your loop for i?

whichen commented 5 years ago

Would type(obj) not be easiest inside your loop for i?

Thanks for your reply. All the type of i are the same "Endpoint.DataSet". But in fact, every i has different heard, I want to get special one. Any one can help?

swar commented 5 years ago

Can you provide a link to a documentation page. I'm not understanding what you mean by 'LastMeeting', 'LineScore'

whichen commented 5 years ago

Can you provide a link to a documentation page. I'm not understanding what you mean by 'LastMeeting', 'LineScore'

Thanks for your reply. FYI https://github.com/swar/nba_api/blob/cc43a9471619cf6124413a01da20de5095b428f6/nba_api/stats/endpoints/scoreboardv2.py There are different types of dataset like: self.last_meeting = Endpoint.DataSet(data=data_sets['LastMeeting']) self.line_score = Endpoint.DataSet(data=data_sets['LineScore']) How can I identify these types in data set?

swar commented 5 years ago

Endpoint.DataSet is an object that I created that you can find here. This object is used to store and retrieve the data easily.

However, I think you're referring to the specific data_sets. So you could iterate over each data_set and then grab the dict/json/dataframe and find the types for their columns. This might not be 100% accurate though. As you can see, the Season / Year in some cases is stored as a string. https://stats.nba.com/stats/scoreboardv2?DayOffset=0&GameDate=2018-10-08&LeagueID=00

Below is the code that I created quickly to pull all the data_sets as well as show the types for each column in the data_set. No columns will be showed for data_sets without any data, because there is nothing to identify.

from nba_api.stats.endpoints.scoreboardv2 import ScoreboardV2

scoreboard = ScoreboardV2(game_date='2018-10-08')
data_sets = scoreboard.get_normalized_dict()
for data_set in data_sets:
    print("----------------------------------")
    print(data_set)
    data = data_sets[data_set]
    if data:
        first_row = data[0]
        for column_name in first_row:
            print(column_name, type(first_row[column_name]))
whichen commented 5 years ago

Endpoint.DataSet is an object that I created that you can find here. This object is used to store and retrieve the data easily.

However, I think you're referring to the specific data_sets. So you could iterate over each data_set and then grab the dict/json/dataframe and find the types for their columns. This might not be 100% accurate though. As you can see, the Season / Year in some cases is stored as a string. https://stats.nba.com/stats/scoreboardv2?DayOffset=0&GameDate=2018-10-08&LeagueID=00

Below is the code that I created quickly to pull all the data_sets as well as show the types for each column in the data_set. No columns will be showed for data_sets without any data, because there is nothing to identify.

from nba_api.stats.endpoints.scoreboardv2 import ScoreboardV2

scoreboard = ScoreboardV2(game_date='2018-10-08')
data_sets = scoreboard.get_normalized_dict()
for data_set in data_sets:
    print("----------------------------------")
    print(data_set)
    data = data_sets[data_set]
    if data:
        first_row = data[0]
        for column_name in first_row:
            print(column_name, type(first_row[column_name]))

Thank you, Swar.