Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Prakash1050
Helper III
Helper III

String indices must be integers

Hi All, 

 

     

String indices must be integers
This is my code :

 

Prakash1050_0-1719308730684.png

This code output :

Prakash1050_1-1719308755993.png

 

What i need is....,

 

I need to fetch the ticker values from the output in the ticker_sentiment json format values that is in the below.

 

[{ticker=MSFT, ticker_sentiment_label=Somewhat-Bullish, ticker_sentiment_score=0.163239, relevance_score=0.04028}, {ticker=NVDA, ticker_sentiment_label=Somewhat-Bullish, ticker_sentiment_score=0.235239, relevance_score=0.48854}, {ticker=VMW, ticker_sentiment_label=Neutral, ticker_sentiment_score=0.056248, relevance_score=0.04028}, {ticker=AVGO, ticker_sentiment_label=Somewhat-Bullish, ticker_sentiment_score=0.274491, relevance_score=0.520477}]

 

Prakash1050_2-1719308984277.png

 

I need output is MSFT. So,

 

I Witten this code :    print(news_json_1["json_object"]["ticker_sentiment"][0])

this code output is : [

so, I written this code :    print(news_json_1["json_object"]["ticker_sentiment"]["ticker"])

this code got error :     TypeError     Traceback          (most recent call last)

       print(news_json_1["json_object"]["time_published"])

        print(news_json_1["json_object"]["url"])

---> print(news_json_1["json_object"]["ticker_sentiment"][0]["ticker"])

 

TypeError: string indices must be integers

 

How to fetch the first ticker?

Please help me.

Thanks in advance.

I need to fetch the ticker value from the output.

2 REPLIES 2
lbendlin
Super User
Super User

lbendlin_0-1719334123979.png

 

The value of ticker_sentiment is a string, not an array. You will need to parse that string again as JSON before you can access the first item in the array.

Thanks for your reply. 

Prakash1050_0-1719378122069.png

Here, I already convert into json. But, I don't know why the value of ticker_sentiment is still string.

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.