I have a data frame with a tfidf_sorted column as follows:
tfidf_sorted 0 [(morrell, 45.9736796), (football, 25.58352014... 1 [(melatonin, 48.0010051405), (lewy, 27.5842077... 2 [(blues, 36.5746634797), (harpdog, 20.58669641... 3 [(lem, 35.1570832476), (rottensteiner, 30.8800... 4 [(genka, 51.4667410433), (legendaarne, 30.8800...
type(df.tfidf_sorted) returns pandas.core.series.Series .
This column was created as follows:
df['tfidf_sorted'] = df['tfidf'].apply(lambda y: sorted(y.items(), key=lambda x: x[1], reverse=True))
where tfidf is a dictionary.
How to get the first 10 key-value pairs from tfidf_sorted ?
source share