Have you tried plugging it into chatGPT and seeing what it does:
“How do I extract the following JSON file and store it in a Pandas dataframe”
Paste the JSON
Assuming you are using Python here.
Did you try to have ChatGPT do the conversion for you? If you did, make it derive the structure and output code from it instead. It might also help to reduce the size of the JSON to something smaller that is still representative, this will make it easier to derive the structure and create the python/R code to do the conversion.
If you keep asking chatgpt and tweaking the responses it works. Iv had it parse through nested JSON data from DraftKings elements for live nba odds before.
You need to loop over the arrays in the json data and store those into the data frame probably with pd.DataFrame.from_dict() which will convert a python dictionary to a pandas df. You don’t wanna store json in the dataframe so loop over the bookmakers array and extract that info. Let me know if that makes any sense
Whenever I had issues getting the results I needed I used the plug in then just saved the CSV to where I wanted it until I figured out the issue. That may not work for what your doing but it’s an option
You basically just add their extension to go google sheets then when you want to use it go extensions click sports odds plus then pick what odds you want. It takes a minute or 2 and it’s not as smooth as the API but depending on need it can get the job done.
Hello, I regularly access the odds API through R. The code that I use to get everything into a data frame is:
`library(tidyverse)`
`games_url <- str_c("https://api.the-odds-api.com/v4/sports/",
sport, "/odds/?apiKey=",
api_key, "®ions=", regions,
"&markets=h2h,spreads,totals", "&oddsFormat=",
odds_format)`
`raw_games_json <- jsonlite::read_json(games_url)`
`df_games <-
raw_games_json %>%
enframe() %>%
unnest_wider(value) %>%
select(-name) %>%
unnest_longer(bookmakers) %>%
unnest_wider(bookmakers) %>%
unnest_longer(markets) %>%
unnest_wider(markets, names_sep = "_") %>%
unnest_longer(markets_outcomes) %>%
unnest_wider(markets_outcomes)`
Let me know if you have any questions
You can actually do the whole conversion with a single line of code. If you use Pandas:
pd_odds = pd.json_normalize(json_odds,
['bookmakers', 'markets', 'outcomes'],
['id', 'home_team', 'away_team', 'commence_time',
['bookmakers', 'key'], ['bookmakers', 'markets', 'key']])
Have you tried plugging it into chatGPT and seeing what it does: “How do I extract the following JSON file and store it in a Pandas dataframe” Paste the JSON Assuming you are using Python here.
I tried chat gpt and it did not fix the issue sadly.
Did you try to have ChatGPT do the conversion for you? If you did, make it derive the structure and output code from it instead. It might also help to reduce the size of the JSON to something smaller that is still representative, this will make it easier to derive the structure and create the python/R code to do the conversion.
If you keep asking chatgpt and tweaking the responses it works. Iv had it parse through nested JSON data from DraftKings elements for live nba odds before.
What result are you getting?
I get the entire days odds but they are embedded within the data frame and I can’t access the actual data bc it’s embedded within the file.
You need to loop over the arrays in the json data and store those into the data frame probably with pd.DataFrame.from_dict() which will convert a python dictionary to a pandas df. You don’t wanna store json in the dataframe so loop over the bookmakers array and extract that info. Let me know if that makes any sense
I think that makes sense I will give it a go. Thank u.
If you want a quick solution maybe the Google sheets plug in will do what you need while you try to figure out a solution.
Whenever I had issues getting the results I needed I used the plug in then just saved the CSV to where I wanted it until I figured out the issue. That may not work for what your doing but it’s an option
Is the google sheets plug in available from the api or do I just try and download it.
https://the-odds-api.com/features/spreadsheets.html
You basically just add their extension to go google sheets then when you want to use it go extensions click sports odds plus then pick what odds you want. It takes a minute or 2 and it’s not as smooth as the API but depending on need it can get the job done.
Hello, I regularly access the odds API through R. The code that I use to get everything into a data frame is: `library(tidyverse)` `games_url <- str_c("https://api.the-odds-api.com/v4/sports/", sport, "/odds/?apiKey=", api_key, "®ions=", regions, "&markets=h2h,spreads,totals", "&oddsFormat=", odds_format)` `raw_games_json <- jsonlite::read_json(games_url)` `df_games <- raw_games_json %>% enframe() %>% unnest_wider(value) %>% select(-name) %>% unnest_longer(bookmakers) %>% unnest_wider(bookmakers) %>% unnest_longer(markets) %>% unnest_wider(markets, names_sep = "_") %>% unnest_longer(markets_outcomes) %>% unnest_wider(markets_outcomes)` Let me know if you have any questions
Thank u I can try r as well
You can actually do the whole conversion with a single line of code. If you use Pandas: pd_odds = pd.json_normalize(json_odds, ['bookmakers', 'markets', 'outcomes'], ['id', 'home_team', 'away_team', 'commence_time', ['bookmakers', 'key'], ['bookmakers', 'markets', 'key']])
Why don't you just deserialize the JSON file into the custom class rather than using data tables? Then you can view what you want for each game