Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 23131

TypeError: list indices must be integers or slices, not str. Using record_path

$
0
0

I've recently encountered a problem and can't seem to solve it. In my project I need to set the index of my pandas dataframe to a variable found in a Json file. The JSON file i'm using looks like this:

{"data": {"events": [        {"id": "3745060","externalIds": [                {"id": "10244973","provider": "betgenius"                },                {"id": "sr:match:41888589","provider": "betradar"                }            ],"extKey": null,"retailCode": null,"name": "Norwich City FC v Ipswich Town",

From this file I need to extract the variable 'name'. In an attempt to use this I used the following lines of code:

api = 'https://content.toto.nl/content-service/api/v1/q/event-list?startTimeFrom=2024-04-05T22%3A00%3A00Z&started=false&maxMarkets=10&orderMarketsBy=displayOrder&marketSortsIncluded=--%2CCS%2CDC%2CDN%2CHH%2CHL%2CMH%2CMR%2CWH&marketGroupTypesIncluded=CUSTOM_GROUP%2CDOUBLE_CHANCE%2CDRAW_NO_BET%2CMATCH_RESULT%2CMATCH_WINNER%2CMONEYLINE%2CROLLING_SPREAD%2CROLLING_TOTAL%2CSTATIC_SPREAD%2CSTATIC_TOTAL&eventSortsIncluded=MTCH&includeChildMarkets=true&prioritisePrimaryMarkets=true&includeCommentary=true&includeMedia=true&drilldownTagIds=691&excludeDrilldownTagIds=7291%2C7294%2C7300%2C7303%2C7306're = r.get(api)red = re.json()df = pd.json_normalize(red, record_path=['data', 'events'], meta=[['data', 'events', 'markets', 'outcomes', 'type'], ['data', 'events', 'markets', 'outcomes', 'subType'], ['data', 'events', 'name']])#meta_col = 'data.events.markets.outcomes.type'#meta_thuis = 'data.events.markets.outcomes.subType'game = df['name']print(game)

I've used similar code for different JSON files and different variables and have never encountered this problem. No idea what's the next step in solving this so definitely could use some help <3


Viewing all articles
Browse latest Browse all 23131

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>