0Pricing
Data Science Academy · 课时

计数并发现值

使用 value_counts、unique 和快速检查

计数并发现值 是 CoddyKit 上的免费 Data Science Academy 课时。 这是第 4 节课,共 4 节。 你可以在下方免费阅读本课时的完整内容 — 然后在浏览器中使用内置代码编辑器和全天候 AI 导师进行实践。 这是 Data Science Academy 学习路径的一部分,你的进度在网页和 CoddyKit 应用中同步。 Data Science Academy 课程共包含 4 节课。

本课时的部分内容尚未翻译,以英文显示。

Get to Know Your Column

Before any analysis, you want a feel for what is inside a Series. A few quick methods summarize the contents in seconds. 🔍

A Sample Series

Here is a Series of fruit names with some repeats. We will explore its contents with handy built-in methods.

import pandas as pd
s = pd.Series(['apple', 'pear', 'apple', 'fig', 'pear', 'apple'])

Count Each Value

The value_counts method tallies how often each value appears, sorted from most to least common. It is the fastest frequency check.

print(s.value_counts())

See the Distinct Set

Call unique to get every distinct value just once, in the order first seen. It answers what kinds of values you have.

print(s.unique())

How Many Distinct

The nunique method returns the count of distinct values as a single number. Here it tells you how many fruit kinds exist.

print(s.nunique())

Shares Instead of Counts

Add normalize=True to value_counts and you get proportions instead of raw counts. Now each fruit's share sums to one.

print(s.value_counts(normalize=True))

Spot Missing Values

The isna method flags each value that is missing as True. Summing those flags counts the gaps in your column at a glance.

nums = pd.Series([1.0, None, 3.0])
print(nums.isna().sum())

Check Membership

Use isin with a list to test which values belong to a chosen set. It returns a boolean mask you can filter with later.

print(s.isin(['apple', 'fig']))

Find the Extremes

For numbers, max and min surface the largest and smallest values instantly, without sorting the whole Series yourself.

print(nums.max(), nums.min())

One-Shot Overview

The describe method bundles count, unique, top, and frequency for text, giving a tidy snapshot in a single call. 📋

print(s.describe())

Your Inspection Toolkit

Together these methods are your first inspection pass on any column. A minute spent here saves hours of confused analysis later. 🧰

Quick Check

Pick the right tool for a frequency tally.

Recap

You can now profile a Series with value_counts, unique, nunique, isna, and isin. These quick checks reveal what your data holds. Well done! 🎉

常见问题解答

「计数并发现值」课时是免费的吗?

是的 — 「计数并发现值」的完整文本可在网页上免费阅读。要进行交互式练习(内置代码编辑器和全天候 AI 导师)并解锁 Data Science Academy 课程的其余内容,请升级到 CoddyKit PRO。 Data Science Academy 课程共包含 4 节课。

「计数并发现值」这节课中我会学到什么?

使用 value_counts、unique 和快速检查 你通过在浏览器中直接运行的动手代码来练习 Data Science Academy,全天候 AI 导师会在你学习这节课的过程中回答你的问题。

学习 Data Science Academy 需要有经验吗?

无需任何先前经验。CoddyKit 上的 Data Science Academy 课程适合初学者到高级学习者,你可以从这里开始或从头开始,按照自己的节奏学习。 这是第 4 节课,共 4 节。

「计数并发现值」课时需要多长时间?

大多数 CoddyKit 课程大约需要 5–10 分钟。每节课都很精短且互动,所以你能稳步进步,并在网页和应用中从离开的地方继续。

我能在这节 Data Science Academy 课中编写并运行代码吗?

能。每节 Data Science Academy 课都包含内置代码编辑器,你可以在浏览器中直接编写并运行真实代码,并获得即时 AI 反馈 — 无需本地设置。

此课程中的所有课时

  1. 带名称和索引的列
  2. 基于标签与基于位置的访问
  3. Series 运算与对齐
  4. 计数并发现值
← 返回 Data Science Academy