Sortowanie według jednej lub wielu kolumn
Kolejność rosnąca, malejąca i remisy
Sortowanie według jednej lub wielu kolumn to bezpłatna lekcja Data Science Academy na CoddyKit. To lekcja 1 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.
Order Brings Insight
Raw rows arrive in no useful order. Sorting puts the most interesting records on top so patterns jump out at a glance. 🔎
sort_values Is Your Tool
In pandas you reorder rows with sort_values. You name the column to sort by, and pandas hands back a freshly ordered DataFrame.
df.sort_values("price")Ascending by Default
By default sort_values goes smallest to largest. So numbers climb upward and text sorts alphabetically from A to Z.
Flip to Descending
Set ascending=False when you want the biggest values first, like the top-selling products or the highest scores.
df.sort_values("sales", ascending=False)Sort by Many Columns
Pass a list of columns and pandas sorts by the first, then breaks ties using the next, and so on down the list.
df.sort_values(["region", "sales"])Mixed Sort Directions
Give ascending a list too, one flag per column. That lets you sort region A to Z while sales go high to low.
df.sort_values(["region", "sales"], ascending=[True, False])A New Frame, Not In Place
By default sort_values returns a sorted copy and leaves the original untouched, so your source data stays safe.
Sort In Place If You Mean It
Add inplace=True to rewrite the original DataFrame instead of returning a copy. Use it only when you truly want that.
Watch the Index
Sorting keeps each row label glued to its data, so the index looks shuffled afterward. That is expected, not a bug.
Reset for Clean Numbers
Want tidy 0,1,2 labels after sorting? Chain reset_index with drop=True to renumber rows from the top.
df.sort_values("sales").reset_index(drop=True)Where NaN Values Land
Missing values sink to the bottom by default. Set na_position to first if you would rather see them up top.
Quick Check
You want the highest sales on top. How do you sort?
Recap: Sorting Made Simple
You now sort with sort_values, flip with ascending, break ties using a column list, and tidy labels with reset_index. Nicely done! 🎉
Często zadawane pytania
Czy lekcja „Sortowanie według jednej lub wielu kolumn” jest bezpłatna?
Tak — pełny tekst „Sortowanie według jednej lub wielu kolumn” 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 „Sortowanie według jednej lub wielu kolumn”?
Kolejność rosnąca, malejąca i remisy Ć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 1 z 4.
Ile czasu zajmuje lekcja „Sortowanie według jednej lub wielu kolumn”?
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
- Sortowanie według jednej lub wielu kolumn
- Pierwsze podsumowanie groupby
- Wykresy liniowe i słupkowe w matplotlib
- Etykiety, tytuły i legendy