1. Home
  2. Data Science
  3. Pandas
  4. What does df["city"].value_counts() return in pandas?

Added 30 Nov -0001

What does df["city"].value_counts() return in pandas?

  1. The unique values without any counts attached
  2. The number of NaN entries in the column only
  3. Counts per distinct value, sorted most frequent first Correct answer
  4. Counts per distinct value, sorted in alphabetical order

Correct answer

C. Counts per distinct value, sorted most frequent first

13 views

MCQSEXAM

Explanation

value_counts produces a Series whose index holds the distinct values and whose values hold their frequencies, ordered from most to least common by default. Pass normalize=True to get proportions instead of raw counts, and dropna=False to include missing values, which are excluded otherwise. nunique answers a different question by returning just the number of distinct values.

Reference

Asked in: NTS, PPSC IT, Interviews

Preparing for an exam?

Doubts & discussion

Not sure why the answer is C? Ask here and get an explanation.

Ask a doubt about this MCQ

Shown after review. No links please.

More Pandas MCQs

Practise all Pandas MCQs

Similar MCQs