Merge według kluczy i indeksów
Łączenie według kolumn lub indeksu
Merge według kluczy i indeksów to bezpłatna lekcja Data Science Academy na CoddyKit. To lekcja 2 z 4. Możesz przeczytać całą lekcję poniżej za darmo — a potem ćwiczyć ją interaktywnie w przeglądarce z wbudowanym edytorem kodu i tutorem AI dostępnym 24/7. To część ścieżki edukacyjnej Data Science Academy, a Twój postęp synchronizuje się między webem a aplikacją CoddyKit. Kurs Data Science Academy zawiera 4 lekcji w sumie.
Części tej lekcji nie zostały jeszcze przetłumaczone i są wyświetlane po angielsku.
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!
Często zadawane pytania
Czy lekcja „Merge według kluczy i indeksów” jest bezpłatna?
Tak — pełny tekst „Merge według kluczy i indeksów” jest dostępny za darmo tutaj w sieci. Aby ćwiczyć ją interaktywnie (wbudowany edytor kodu i tutor AI dostępny 24/7) i odblokować resztę kursu Data Science Academy, przejdź na CoddyKit PRO. Kurs Data Science Academy zawiera 4 lekcji w sumie.
Co nauczysz się w „Merge według kluczy i indeksów”?
Łączenie według kolumn lub indeksu Ćwiczysz Data Science Academy z praktycznym kodem, który uruchamiasz bezpośrednio w przeglądarce, a tutor AI dostępny 24/7 odpowiada na Twoje pytania podczas pracy nad lekcją.
Czy potrzebuję doświadczenia, aby zacząć Data Science Academy?
Nie wymagamy żadnego doświadczenia. Data Science Academy w CoddyKit jest strukturyzowany dla początkujących i zaawansowanych użytkowników, więc możesz zacząć tutaj lub od początku i uczyć się w swoim tempie. To lekcja 2 z 4.
Ile czasu zajmuje lekcja „Merge według kluczy i indeksów”?
Większość lekcji CoddyKit trwa około 5–10 minut. Każda lekcja to mały, interaktywny krok, dzięki czemu robisz systematyczne postępy i zawsze wracasz dokładnie do tego samego miejsca — na webie i w aplikacji.
Czy mogę pisać i uruchamiać kod w tej lekcji Data Science Academy?
Tak. Każda lekcja Data Science Academy zawiera wbudowany edytor kodu, więc piszesz i uruchamiasz prawdziwy kod bezpośrednio w przeglądarce i od razu otrzymujesz sprzężenie zwrotne od AI — bez konfiguracji na komputerze.
Wszystkie lekcje w tym kursie
- Inner, left, right i outer
- Merge według kluczy i indeksów
- concat do układania i dołączania
- Diagnozowanie nieprawidłowych złączeń