Calling astype on Python Pandas series with unconvertible values? Use errors=’ignore’ to skip the error:
Python Pandas astype() returns a NEW series — it doesn’t modify in place: Watch out: You’ll get a TypeError if any value can’t be converted
How many NaNs in a Python Pandas data frame? 1. Use isna, returning a data frame of booleans2. Use sum, returning the number of NaNs in each column3. Use sum again, adding those numbers
How many NaNs in a Python Pandas series? Use isna (returns True/False) then sum/value_counts: Hint: Pass normalize=True for the percentage
Remember that Python has two division operators:10 / 2 # truediv, returns float: 5.010 // 2 # floordiv, rounds down: 510 / 3 # truediv: 3.333…10 // 3 # floordiv: 3 Note: // with floats returns a float (10.0 // 3 = 3.0)
Reading CSV into Python Pandas? Pass header to specify the row containing column names: No headers at all? Just pass headers=None: Pass a list for multi-indexed column names:
Python Pandas: pivot vs pivot_table? Both reshape data, but: – pivot: one value per cell (errors if duplicates)– pivot_table: aggregates duplicates (mean, sum, etc.) Use pivot for clean data, pivot_table for real-world messiness.
What’s the difference between join and merge in Python Pandas? • join combines based on the indexes. Perfect when both data frames refer to the same person IDs, product names, or dates• merge combines based on *any* two columns — but you must specify which ones.
Apply different aggregations to each column when grouping on a Python Pandas data frame with agg and a dict:
Apply multiple aggregations when grouping on a Python Pandas data frame with agg: Grouping on 2+ columns? Each method will be applied to each column: