Unable to get nltk or TextBlob working in Power BI

I just took the Python II for Power BI Users course, which was excellent. However, when I attempt to use the same code that was used in the course in Power BI, I get errors such as: ModuleNotFoundError: No module named ‘textblob’ (or nltk when attempt that code). The pbix file wasn’t attached to the course, so I can’t test it to see if I’m missing something. My question is, did Power BI stop supporting those libraries?

error1

Hi @jessbramow ,

Welcome to the forum.

If you try it locally did you try it within Jupyter Notebook first ?
Do you have textblob module install ?

You can check with this Notebook:
Intro to Sentiment Analysis.ipynb (25.9 KB)

if you got error and don’t have TextBlob package it can be install also with Jupyter cell syntax:
!pip install textblob

and try again.

Good luck.

Hotel Review dataset you can find at:

@jessbramow You must have created a new virtual environment where you installed the packages, correct?

IHi @mspanic. Yes, it works perfectly within Jupyter Notebook.

My environment has been created. Power BI has the correct path. And other python visuals work fine within Power BI. Just not the nltk or TextBlob code. :frowning:

@jessbramow share the code

Hi @jessbramow ,

After Get data,

and then in PowerQuery go under Transfor → Run Python code

in Python II course script is

from textblob import TextBlob

def get_sentiment(sentence):
    score = TextBlob(sentence).sentiment.polarity
    return score 

dataset['Sentiment']= dataset['title'].apply(get_sentiment)

Then Ok

check if new column Sentiment is decimal type if not change it and on the dashboard example average of this column is used

In course example

image

and then you need to go to table

image

to expand the data

Pbix Example:

Sentiment_Example.pbix (27.1 MB)

Hello @jessbramow

Good to see that you are having progress with your inquiry. Did the responses from @mspanic and @AntrikshSharma help you solve your inquiry?

If it does, kindly mark as the solution the answer that solved your query.

If not, how far did you get and what kind of help do you need further?

My apologies. I thought I had replied to this last week but I don’t see my response. I am using your pbix file and I am getting the exact same error that I get on my code. "No module named ‘textblob’. I know that Textblob is installed in my environment, so I’m really not sure why this isn’t working. But it is super frustrating!

Hi @jessbramow ,

I understand your frustration - I also need some time to set up all to work.

It looks like you need additional set up for PowerBI to work with Python scripts

I need to change also Windows System Environment Variable PATH and add :

C:\Users\AppData\Local\Continuum\Anaconda3\Scripts\

C:\Users\AppData\Local\Continuum\Anaconda3\Library\

C:\Users\AppData\Local\Continuum\Anaconda3\Library\bin\

C:\Users\AppData\Local\Continuum\Anaconda3\Library\mingw-w64\bin\

Details are described at :

https://forum.enterprisedna.co/t/how-to-use-emojis-no-module-named-emoji/28071/4

Good luck, and please let us know the results.
Thanks.

1 Like

Thank you so much @mspanic. This seems to have done the trick. I can at least run it on one of my columns. I’m having encoding problems with another column, but I think I should be able to figure that one out! I greatly appreciate your help!

1 Like

@jessbramow - Great that you finally managed to find start solution.
If problem with another column persists do not hesitate to open new topic.

Good luck