When customer reviews are in Portuguese, the language is a processing requirement, not just a detail to mention in a prompt. Counting common words calls for Portuguese stopwords and a Portuguese tokenizer; searching for positive feedback calls for Portuguese terms whose meanings fit the review context. section 5.3.4 section 5.5.3
For a Python word-frequency workflow:
- Identify the DataFrame column containing the reviews, such as review_comment_message, and tell the AI assistant that its contents are in Portuguese. section 5.3.4
- Check the generated code for both stopwords.words('portuguese') and word_tokenize(text.lower(), language='portuguese'). Specifying the language in the prompt did not make the first generated tokenizer use it. section 5.3.4
- Inspect the resulting words and counts rather than assuming that language-specific code produces useful findings. section 5.3.4
import pandas as pd
import nltk
from nltk.corpus import stopwords
from nltk.tokenize import word_tokenize
from collections import Counter
# Make sure to download Portuguese stopwords
nltk.download('stopwords')
nltk.download('punkt')
# Load your DataFrame
df = pd.read_csv('olist_order_reviews_dataset.csv')
# Preprocessing function
def preprocess_text(text):
# Tokenize, convert to lowercase, and remove punctuation
tokens = word_tokenize(text.lower(), language='portuguese')
words = [word for word in tokens if word.isalpha()]
# Remove Portuguese stopwords
stop_words = set(stopwords.words('portuguese'))
filtered_words = [word for word in words if word not in stop_words]
return filtered_words
# Apply preprocessing to the 'review_comment_message' column
df['processed_review'] =
df['review_comment_message'].apply(preprocess_text)
# Calculate word frequencies
word_freq = Counter()
for _, row in df.iterrows():
word_freq.update(row['processed_review'])
# Print the most common words and their frequencies
print(word_freq.most_common(10))
The corrected listing shows the consequential tokenizer argument, language='portuguese', alongside Portuguese stopword removal. Inspect the complete code before running it. section 5.3.4
Finding positive reviews
A keyword request can return excelente (“excellent”), ótimo (“great”), and vale a pena (“worth it”). These are candidates for searching reviews, not proof that every matching review is positive: check the surrounding words and allow for inflections and contractions. section 5.5.3
For broader sentiment analysis, possible Portuguese lexicons include OPINLEX and SentiLex; a Portuguese version of LIWC is also mentioned but requires purchase. Check whether a resource is available and suitable before relying on it: non-English lexicons can be difficult to locate, and academic tools may cease to be maintained. section 5.6.2
