concept document frequency in category data

This is an excerpt from Manning's book Data Science Bookcamp: Five Python Projects.
Three of the 34 words appear have document frequency that’s greater than 0.1. As expected, these words are very general, and not car-specific. We thus can utilize document frequencies for ranking purposes. Lets rank our words by relevance, in the following manner. First, we’ll sort the word by count, from greatest to smallest. Afterwards, all words with equal count will be sorted by document frequency, from smallest to greatest. In Pandas, we can execute this dual-column sorting by running
df.sort_values(['Count', 'Document Frequency'], ascending=[True, False]).Listing 15.21. Ranking words by both count and document frequency
df_sorted = df.sort_values(['Count', 'Document Frequency'], ascending=[False, True]) print(df_sorted[:10].to_string(index=False))Word Count Document Frequency car 4 0.047375 tellme 1 0.000177 bricklin 1 0.000354 funky 1 0.000619 60s 1 0.001591 70s 1 0.001856 enlighten 1 0.002210 bumper 1 0.002298 doors 1 0.005922 production 1 0.008397Our sorting was successful. New car-related words, such as bumper, are now present in our list of top-ranked words. However, the actual sorting procedure was rather convoluted. It required us to sort 2 columns separately. Perhaps, we can simplify the process by combining the word counts and document frequencies into a single score. How can we combine these values? One approach is to divide each word-count by its associated document frequency. This resulting value will increase if:
This isn’t necessarily true of smaller datasets, where the number of documents is low, and the document frequency is high. Consequently, the IDF might be too small to meaningfully improve the clustering results.