0Pricing
Data Science Academy · レッスン

数値をカテゴリに分ける

範囲の区切りにcutとqcutを使う

「数値をカテゴリに分ける」はCoddyKit上の無料Data Science Academyレッスンです。 これはレッスン1/4です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応のAIチューターでハンズオン演習できます。 これはData Science Academy学習パスの一部であり、ウェブとCoddyKitアプリ全体で進捗が同期されます。 Data Science Academyコースには全4レッスンが含まれています。

このレッスンの一部はまだ翻訳されておらず、英語で表示されています。

Why Bin a Number

Sometimes a raw number like age tells you less than a label like young or senior. Binning turns a continuous value into tidy groups. 🪣

Bins Reveal Patterns

Models and charts often read categories more clearly than exact figures. Grouping prices into low, mid, and high can surface trends you would otherwise miss.

Meet pandas cut

The cut function slices a column into bins you define by edges. You give it the boundaries, and it labels each value for you.

import pandas as pd
ages = pd.Series([7, 22, 45, 70])
bins = pd.cut(ages, [0, 18, 60, 100])

Name Your Bins

Pass labels so each bin has a friendly name instead of an interval. Now your output reads like a real category, not a math range.

pd.cut(ages, [0, 18, 60, 100],
       labels=['child', 'adult', 'senior'])

Edges Are Inclusive Right

By default cut includes the right edge of each bin and excludes the left. So a value of 18 lands in the first bin, not the second.

Flip With right=False

Want the left edge included instead? Set right=False and the boundary behavior flips, so 18 moves into the next bin up.

pd.cut(ages, [0, 18, 60, 100], right=False)

Equal-Width Bins

Give cut a single number instead of edges and it creates that many equal-width bins automatically across the value range.

pd.cut(ages, 4)

Meet pandas qcut

The qcut function splits by quantiles, so each bin holds roughly the same number of rows. Great when your data is lopsided.

pd.qcut(ages, 4)

cut vs qcut

Use cut for fixed, meaningful edges like price tiers. Use qcut when you want balanced groups such as quartiles of income.

Bins Become a Feature

The result is a categorical column you can drop straight into your DataFrame and feed to grouping, plotting, or a model.

df['age_group'] = pd.cut(df['age'],
                         [0, 18, 60, 100])

Watch the Out-of-Range

Values outside your bin edges become NaN. Always set edges that cover your real minimum and maximum, or you will silently lose rows.

Quick Check

You want four groups that each hold about the same number of rows. Which tool fits?

Recap: Binning

You learned to group numbers into labels: cut for chosen edges and equal widths, qcut for equal counts. Mind the edges and you turn raw values into useful features. 🎉

よくある質問

「数値をカテゴリに分ける」レッスンは無料ですか?

はい。「数値をカテゴリに分ける」の完全なテキストはこのウェブで無料で読めます。インタラクティブに演習し(組み込みコードエディタと24時間対応のAIチューター)、Data Science Academyコースの残りをアンロックするには、CoddyKit PROにアップグレードしてください。 Data Science Academyコースには全4レッスンが含まれています。

「数値をカテゴリに分ける」で何を学びますか?

範囲の区切りにcutとqcutを使う ブラウザで直接実行するハンズオンコードでData Science Academyを演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。

Data Science Academyを始めるのに経験は必要ですか?

事前経験は必要ありません。CoddyKitのData Science Academyは初級者から上級者向けに構成されているため、ここから始めるか最初から始めて、自分のペースで進むことができます。 これはレッスン1/4です。

「数値をカテゴリに分ける」レッスンにはどのくらい時間がかかりますか?

ほとんどのCoddyKitレッスンは約5~10分かかります。各レッスンはコンパクトでインタラクティブなので、着実に進歩し、ウェブとアプリ全体で正確に前回の場所から再開できます。

このData Science Academyレッスンでコードを書いて実行できますか?

はい。すべてのData Science Academyレッスンに組み込みコードエディタが含まれているため、ブラウザでリアルコードを書いて実行し、即座のAIフィードバックを取得できます。ローカル設定は不要です。

このコースのすべてのレッスン

  1. 数値をカテゴリに分ける
  2. カテゴリ列をエンコードする
  3. 数値をスケーリングして正規化する
  4. 日付とテキストから特徴量を作る
← Data Science Academyに戻る