0Pricing
Data Science Academy · レッスン

キーとインデックスでmergeする

列またはインデックスで結合する

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

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

Same Name, One Word

When both tables share a column with the same name, on is all you need to merge them together.

orders.merge(customers, on="customer_id")

Join on Many Keys

Sometimes one column is not enough. Pass a list to on and pandas matches rows on every key at once.

sales.merge(targets, on=["region", "month"])

Different Names, No Problem

When key columns are named differently, use left_on and right_on to tell pandas which column maps to which.

orders.merge(users, left_on="uid", right_on="id")

A Leftover Column

With left_on and right_on, both key columns survive in the result. You often drop the duplicate afterward.

merged.drop(columns="id")

The Index Can Be a Key Too

If your key lives in the index instead of a column, set left_index or right_index to True to join on it.

orders.merge(prices, left_on="sku", right_index=True)

join for Index Merges

For two index-aligned tables, the join method is shorter. It merges on the index by default.

left.join(right)

Handle Overlapping Names

When both tables have a column with the same name, pandas adds suffixes so the two versions stay distinct.

a.merge(b, on="id", suffixes=("_a", "_b"))

Keys Must Share a Type

A common surprise: a key stored as a string on one side and an integer on the other will simply never match.

Mind Duplicate Keys

If a key value repeats on both sides, merge produces every matching pair. Rows can multiply unexpectedly.

join Defaults to Left

Unlike merge, the join method uses a left join by default. Pass how to change it when you need to.

left.join(right, how="outer")

Pick the Right Tool

Use merge for column keys with full control, and join when both tables are already aligned on their index. 🔧

Quick Check

Your key columns have different names in each table. What do you use?

Recap: Matching the Keys

You can merge on shared columns, mismatched names, or the index, and use suffixes to keep overlapping columns clear. Nicely done!

よくある質問

「キーとインデックスでmergeする」レッスンは無料ですか?

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

「キーとインデックスでmergeする」で何を学びますか?

列またはインデックスで結合する ブラウザで直接実行するハンズオンコードでData Science Academyを演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。

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

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

「キーとインデックスでmergeする」レッスンにはどのくらい時間がかかりますか?

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

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

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

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

  1. Inner、Left、Right、Outer
  2. キーとインデックスでmergeする
  3. concatで積み重ねと追加を行う
  4. 不適切なjoinを診断する
← Data Science Academyに戻る