Try this:
from sklearn.feature_extraction.text import TfidfVectorizer
vect = TfidfVectorizer(sublinear_tf=True, analyzer='word', stop_words='english',
tokenizer=tokenize,
strip_accents='ascii',dtype=np.float16)
X = vect.fit_transform(df.pop('Phrase')) # NOTE: `.toarray()` was removed
for i, col in enumerate(vect.get_feature_names()):
df[col] = pd.SparseSeries(X[:, i].toarray().reshape(-1,), fill_value=0)
UPDATE: for Pandas 0.20+ we can construct SparseDataFrame
directly from sparse arrays:
from sklearn.feature_extraction.text import TfidfVectorizer
vect = TfidfVectorizer(sublinear_tf=True, analyzer='word', stop_words='english',
tokenizer=tokenize,
strip_accents='ascii',dtype=np.float16)
df = pd.SparseDataFrame(vect.fit_transform(df.pop('Phrase')),
columns=vect.get_feature_names(),
index=df.index)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…