Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AttributeError: head not found when printing head() in Python

import sklearn

Maybe I'm not understanding something fundamental here, and I just don't know what that may be. How should I go about debugging this?

messages_tfidf = tfidf_transformer.transform(messages_bow)
print messages_tfidf

That part works fine, as intended. But I run into trouble when I test my understanding of .head()

print messages_tfidf.head()

Outputs the error

AttributeError Traceback (most recent call last) 1 messages_tfidf = tfidf_transformer.transform(messages_bow) 2 print messages_tfidf ----> 3 print messages_tfidf.head()

AttributeError: head not found

Can someone help me understand my logical gap here?

like image 804
treefiddy Avatar asked Aug 04 '26 08:08

treefiddy


1 Answers

Head is a function of pandas DataFrame.

You can do something like that:

import pandas as pd

dframe = pd.DataFrame(messages_tfidf)
dframe.head()

Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!