Python Programing
Pandas Cheatsheet
Pandas Cheatsheet
Cheatsheet 1
In pandas, there are a few quick + reliable ways to check the data type of columns, depending on what you need.
1️⃣ Check all column types (most common)
Output example
2️⃣ Detailed overview (very useful for debugging)
df.info()
Shows:
-
column name
-
non-null count
-
dtype
-
memory usage
3️⃣ Check type of a single column
or
4️⃣ Check only numeric / non-numeric columns
5️⃣ Check if a column is a specific type
6️⃣ Count how many columns per dtype
7️⃣ Detect mixed or problematic types (object columns)
Useful when:
-
CSV imported badly
-
numbers stored as strings
-
mixed types in one column
| Task | Command |
|---|---|
| See all dtypes | df.dtypes |
| Full summary | df.info() |
| Single column | df[col].dtype |
| Only numeric | select_dtypes() |
| Type check |
|
Cheatsheet 2
Oke, ini cheat-sheet Python (pandas) buat subset, grouping, dan filtering — dari paling dasar sampai yang sering dipakai di data real. Contohnya aku sesuaikan dengan data kamu (provinsi, kab, gender, dll).
1️⃣ SUBSET (ambil sebagian data)
a) Subset kolom
b) Subset baris (index-based)
c) Subset baris + kondisi
2️⃣ FILTER (kondisi logika)
a) Filter satu kondisi
b) Multiple kondisi (&, |)
⚠️ WAJIB pakai tanda kurung!
c) Filter dengan isin
d) Filter string (contains, startswith)
e) Filter angka
3️⃣ GROUPING (ringkas data)
a) Group by satu kolom
Sama dengan:
b) Group + agregasi
c) Group by multiple kolom
d) Banyak agregasi sekaligus
4️⃣ SUBSET + GROUP + FILTER (REAL CASE)
❓ Jumlah kelompok per provinsi, hanya yang > 1000
❓ Distribusi gender per provinsi
❓ Kelompok perempuan di Jawa Barat
5️⃣ FILTER DENGAN query() (lebih readable)
Dengan in:
6️⃣ GROUP + FILTER (HAVING-style)
Contoh: provinsi dengan ≥ 100 kelompok perempuan
7️⃣ Best practice (penting banget)
✔️ Jangan lupa normalisasi dulu
✔️ Hindari chained indexing
❌
✔️