Has anybody seen this error?
I did this to define.
GRADED FUNCTION: parse_data_from_file
def parse_data_from_file(filename):
“”"
Extracts sentences and labels from a CSV file
Args:
filename (string): path to the CSV file
Returns:
sentences, labels (list of string, list of string): tuple containing lists of sentences and labels
"""
sentences = []
labels = []
with open("./bbc-text.csv", 'r') as csvfile:
reader = csv.reader(csvfile , delimiter = ',')
next(reader)
for row in reader:
labels.append(row[0])
sentence = row[1]
for word in stopwords:
token = "" + word + ""
sentence = sentence.replace(token , " ")
sentence = sentence.replace ("" , "")
sentences.append(sentence)
### END CODE HERE
return sentences, labels
However, I got this error after testing the function.
Test your function
sentences, labels = parse_data_from_file(filename)
print(f"There are {len(sentences)} sentences in the dataset.\n")
print(f"First sentence has {len(sentences[0].split())} words (after removing stopwords).\n")
print(f"There are {len(labels)} labels in the dataset.\n")
print(f"The first 5 labels are {labels[:5]}")
NameError Traceback (most recent call last)
in
1 # Test your function
----> 2 sentences, labels = parse_data_from_file(filename)
3
4 print(f"There are {len(sentences)} sentences in the dataset.\n")
5 print(f"First sentence has {len(sentences[0].split())} words (after removing stopwords).\n")
NameError: name ‘filename’ is not defined