Reputation: 49
I have a class Netflix
and a method find_popular_category
. However I can't get the method to return the word I'm looking for.
class Netflix:
def find_popular_category(self):
path = os.path.abspath('../data/netflix.csv')
with open(path, encoding= 'utf-8-sig') as file:
open_file = csv.reader(file)
next(file)
lst = []
for x in open_file:
cate = x[10]
lst.append(cate)
spt = [category for word in lst for category in word.split(",")] # splits every word in the string "list"
word_count = Counter(spt) # counts the categories
most = word_count.most_common(1) # gets most categories
print(most)
return most[0][0]
netflix = Netflix()
netflix.find_popular_category()
print(netflix)
Output:
[(' International Movies', 1842)] # This is because of print(most).
<__main__.Netflix object at 0x000001C254E711C8>
# Why doesn't it return only International Movies?
Upvotes: 0
Views: 51
Reputation: 1399
You are trying to print the instance of the Netflix
object. But you need to print the result of the function:
print(netflix.find_popular_category())
Instead of:
print(netflix)
Upvotes: 0
Reputation: 58
It looks like you are just printing the instance of the object. I would assign netflix.find_popular_category() to a variable and print that instead. For example
popularCategory = netflix.find_popular_category()
print(popularCategory)
Upvotes: 2