0Pricing
Data Science Academy · レッスン

Seriesの演算とアラインメント

演算時にラベルが自動で揃う仕組みを学びます

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

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

Math on Whole Columns

You can do math on an entire Series at once. Operations apply to every value together, so there is no loop to write. ⚡

Add a Scalar

Adding a single number to a Series adds it to every value. This broadcast happens automatically across the whole column.

import pandas as pd
s = pd.Series([10, 20, 30])
print(s + 5)

All the Operators Work

Subtraction, multiplication, and division behave the same way. Each one is vectorized, touching all values in a single fast pass.

print(s * 2)

Add Two Series

When you add two Series, pandas lines them up by their index labels first. This step is called alignment and it is the headline feature. 🔗

Matching Labels Combine

Where both Series share a label, their values are combined. Alignment means position does not matter, only the labels do.

a = pd.Series([1, 2], index=['x', 'y'])
b = pd.Series([10, 20], index=['x', 'y'])
print(a + b)

Order Does Not Matter

Even if the labels appear in a different order, pandas still matches them correctly. It pairs label to label, never row to row.

b = pd.Series([20, 10], index=['y', 'x'])
print(a + b)

Missing Labels Make NaN

If a label exists in only one Series, the result for it becomes NaN, meaning Not a Number. There was nothing to pair it with.

c = pd.Series([1], index=['x'])
print(a + c)

Fill the Gaps

Use the .add method with fill_value to treat missing labels as a default instead of NaN. Here zero plugs the holes.

print(a.add(c, fill_value=0))

Apply a Function

Many NumPy functions work directly on a Series and return a new one. Each value is transformed while its index stays intact.

import numpy as np
print(np.sqrt(pd.Series([4, 9, 16])))

Compare to Make Masks

Comparisons also run element-wise, giving a Series of True and False. That boolean mask is the start of filtering data.

print(s > 15)

Why Alignment Wins

Automatic alignment quietly prevents a whole class of bugs from mismatched rows. Trust the labels and let pandas pair them for you. 🛡️

Quick Check

Let's confirm how alignment handles a label gap.

Recap

You saw Series math is vectorized, that operations align by index label, and that unmatched labels yield NaN unless you fill them. Great progress! 🎉

よくある質問

「Seriesの演算とアラインメント」レッスンは無料ですか?

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

「Seriesの演算とアラインメント」で何を学びますか?

演算時にラベルが自動で揃う仕組みを学びます ブラウザで直接実行するハンズオンコードでData Science Academyを演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。

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

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

「Seriesの演算とアラインメント」レッスンにはどのくらい時間がかかりますか?

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

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

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

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

  1. 名前とインデックスを持つ列
  2. ラベルベースと位置ベースのアクセス
  3. Seriesの演算とアラインメント
  4. 値を数えて見つける
← Data Science Academyに戻る