Python Forum

Full Version: ntlk error shown
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
In the following code snippet:

# Instantiate the sentiment intensity analyzer
vader = SentimentIntensityAnalyzer()

# Set column names
columns = ['ticker', 'date', 'time', 'headline']

# Convert the parsed_news list into a DataFrame called 'parsed_and_scored_news'
parsed_and_scored_news = pd.DataFrame(parsed_news, columns=columns)

# Iterate through the headlines and get the polarity scores using vader
scores = parsed_and_scored_news['headline'].apply(vader.polarity_scores).tolist()

# Convert the 'scores' list of dicts into a DataFrame
scores_df = pd.DataFrame(scores)

# Join the DataFrames of the news and the list of dicts
parsed_and_scored_news = parsed_and_scored_news.join(scores_df, rsuffix='_right')

# Convert the date column from string to datetime
parsed_and_scored_news['date'] = pd.to_datetime(parsed_and_scored_news.date).dt.date

parsed_and_scored_news.head()
produces the following error:

Error:
LookupError Traceback (most recent call last) <ipython-input-6-0700d0f789c7> in <module> 1 # Instantiate the sentiment intensity analyzer ----> 2 vader = SentimentIntensityAnalyzer() 3 4 # Set column names 5 columns = ['ticker', 'date', 'time', 'headline'] ~\AppData\Local\Programs\Python\Python37\lib\site-packages\nltk\sentiment\vader.py in __init__(self, lexicon_file) 337 self, lexicon_file="sentiment/vader_lexicon.zip/vader_lexicon/vader_lexicon.txt", 338 ): --> 339 self.lexicon_file = nltk.data.load(lexicon_file) 340 self.lexicon = self.make_lex_dict() 341 self.constants = VaderConstants() ~\AppData\Local\Programs\Python\Python37\lib\site-packages\nltk\data.py in load(resource_url, format, cache, verbose, logic_parser, fstruct_reader, encoding) 750 751 # Load the resource. --> 752 opened_resource = _open(resource_url) 753 754 if format == "raw": ~\AppData\Local\Programs\Python\Python37\lib\site-packages\nltk\data.py in _open(resource_url) 875 876 if protocol is None or protocol.lower() == "nltk": --> 877 return find(path_, path + [""]).open() 878 elif protocol.lower() == "file": 879 # urllib might not use mode='rb', so handle this one ourselves: ~\AppData\Local\Programs\Python\Python37\lib\site-packages\nltk\data.py in find(resource_name, paths) 583 sep = "*" * 70 584 resource_not_found = "\n%s\n%s\n%s\n" % (sep, msg, sep) --> 585 raise LookupError(resource_not_found) 586 587 LookupError: ********************************************************************** Resource vader_lexicon not found. Please use the NLTK Downloader to obtain the resource: >>> import nltk >>> nltk.download('vader_lexicon') For more information see: https://www.nltk.org/data.html Attempted to load sentiment/vader_lexicon.zip/vader_lexicon/vader_lexicon.txt Searched in: - 'C:\\Users\\Newport_j/nltk_data' - 'C:\\Users\\Newport_j\\AppData\\Local\\Programs\\Python\\Python37\\nltk_data' - 'C:\\Users\\Newport_j\\AppData\\Local\\Programs\\Python\\Python37\\share\\nltk_data' - 'C:\\Users\\Newport_j\\AppData\\Local\\Programs\\Python\\Python37\\lib\\nltk_data' - 'C:\\Users\\Newport_j\\AppData\\Roaming\\nltk_data' - 'C:\\nltk_data' - 'D:\\nltk_data' - 'E:\\nltk_data' - '' **********************************************************************
I am not sure what it means when it says:

Error:
Resource vader_lexicon not found. Please use the NLTK Downloader to obtain the resource: >>> import nltk >>> nltk.download('vader_lexicon')
However, nltk 3.5 is installed.

So what must I do to get the error corrected?

Any help appreciated. Thanks in advance.

Respectfully,

ErnestTBass
if a code snippet cannot be run, it's of limited value.
please show all imports, initialization, etc., and please make it so code can be run.
You do what error message say.
So from command line you type python or python3,so it start Python 3.7 Interpreter(interactive mode) that you use.
Then you type what it say in error message.
Example:
>>> import nltk
>>> nltk.download('vader_lexicon')
[nltk_data] Downloading package vader_lexicon to
[nltk_data]     C:\Users\Tom\AppData\Roaming\nltk_data...
True
So next rime run script it will now find vader_lexicon.txt.