BitSize Python · Pandas & NumPy
See your data move.
Hands-on pandas and NumPy, one skill a day, checked in your browser.
| item | qty | price | |
|---|---|---|---|
| 0 | tea | 2 | 2.5 |
| 1 | coffee | 1 | 3.2 |
| 2 | cake | 3 | 3.8 |
| 3 | coffee | 2 | 3.2 |
| 4 | tea | 4 | 2.5 |
| item | qty |
|---|---|
| cake | 3 |
| coffee | 2 |
| tea | 6 |
NumPy essentials
Arrays, dtypes, vectorised maths, broadcasting, masks and axes — the engine under pandas.
- 01 Arrays: one shape, one typenp.array · .dtype · .shape · np.arange · reshape Up next
- 02 Vectorised maths: no loopsa * b · np.round · .sum() · .mean() · a > x Free account
- 03 Broadcasting: shapes that stretchgrid * row · col[:, None] · reshape(-1, 1) · keepdims Free account
- 04 Masks: choosing values by conditiona[a > x] · & | ~ · np.where · a[[i, j]] · np.argsort 🔒 Subscribe
- 05 Axes: which way do you add up?sum(axis=0) · mean(axis=1) · argmax · cumsum · keepdims=True 🔒 Subscribe
The pandas core
Series & DataFrames, .loc and .iloc, filtering, adding and dropping, missing data, dtypes.
- 06 Series: values with labelspd.Series · .index · .values · label lookup · alignment 🔒 Subscribe
- 07 DataFrames: a table of Seriespd.DataFrame · columns · index · set_index · df['col'] 🔒 Subscribe
- 08 First look: inspect before you touchhead · shape · describe · value_counts · nunique · unique 🔒 Subscribe
- 09 .loc: rows and columns by label.loc[rows, cols] · label slices · inclusive end 🔒 Subscribe
- 10 .iloc: rows and columns by position.iloc · position slices · at / iat 🔒 Subscribe
- 11 Filtering rows with conditionsmasks · & | ~ · isin · between 🔒 Subscribe
- 12 query, sorting and the top Nquery · sort_values · nlargest · nsmallest 🔒 Subscribe
- 13 New columns from old onesdf['new'] = … · np.where · np.select · assign 🔒 Subscribe
- 14 Rename, drop — and copies vs viewsrename · drop · inplace · .copy() 🔒 Subscribe
- 15 Missing data: find it firstNaN · isna · notna · isna().sum() · any 🔒 Subscribe
- 16 Filling and dropping gapsdropna · fillna · ffill · interpolate · replace 🔒 Subscribe
- 17 dtypes: make each column the right typedtypes · astype · to_numeric · category 🔒 Subscribe
Text & time
The .str toolkit, extracting and splitting, datetimes, resampling and time windows.
- 18 The .str toolkit: clean text columns.str · strip · lower · title · replace · len · contains 🔒 Subscribe
- 19 Split and extract: pull fields out of textstr.split · expand=True · .str[i] · str.extract · regex groups 🔒 Subscribe
- 20 Dates: parse text into datetimespd.to_datetime · format= · errors='coerce' · datetime64 🔒 Subscribe
- 21 The .dt accessor: pick dates apart.dt.day_name · .dt.hour · .dt.dayofweek · .dt.date · date filters 🔒 Subscribe
- 22 Date maths: gaps, durations, rangesTimedelta · subtract dates · .dt.days · .dt.total_seconds · date_range · DateOffset 🔒 Subscribe
- 23 resample: totals per day and weekset_index · .loc date slices · resample('D') · resample('W') · sum · count 🔒 Subscribe
- 24 Time windows: rolling and day-over-daydaily series · rolling(3) · rolling('7D') · shift · diff · pct_change · cumsum 🔒 Subscribe
Split–apply–combine
groupby with agg and named aggregation, transform, top-N per group.
- 25 groupby: split, apply, combinegroupby · sum · mean · count · size · reset_index 🔒 Subscribe
- 26 Grouping by two keysgroupby([a, b]) · MultiIndex · .loc on groups · sort_values on results 🔒 Subscribe
- 27 agg: several summaries at onceagg(['sum', 'mean']) · named aggregation · per-column functions · lambdas 🔒 Subscribe
- 28 transform: the group's answer on every rowtransform('sum') · share of group · gap to group mean · groupby cumsum · groupby rank 🔒 Subscribe
- 29 Top N per group, and keeping whole groupssort_values + groupby.head · nlargest per group · idxmax · first · filter · apply 🔒 Subscribe
- 30 Groups over time: per week, per itemgroupby with .dt keys · pd.Grouper(freq='W') · groupby + diff · share per period 🔒 Subscribe
Combine & reshape
merge (how, validate), anti-joins, concat, pivot_table, melt, stack and unstack.
- 31 merge: join two tables on a keypd.merge · on= · how='inner' · left_on/right_on · suffixes 🔒 Subscribe
- 32 inner, left, right, outer — and what each one keepshow='left' · 'right' · 'outer' · indicator=True · NaN after a join 🔒 Subscribe
- 33 Safe merges: duplicate keys and validatevalidate='m:1' · duplicated keys · drop_duplicates · multi-key merge 🔒 Subscribe
- 34 Anti-joins: what is missing from the other table_merge · left_only · ~isin · semi-join with isin 🔒 Subscribe
- 35 concat: stack tablespd.concat · ignore_index · keys= · axis=1 · collect then concat once 🔒 Subscribe
- 36 pivot_table: the spreadsheet pivot in pandaspivot_table · index · columns · values · aggfunc · fill_value · margins 🔒 Subscribe
- 37 melt: from wide to longmelt · id_vars · value_vars · var_name · value_name · pivot back 🔒 Subscribe
- 38 stack and unstack: move labels between rows and columnsunstack · stack · MultiIndex · groupby + unstack · level= 🔒 Subscribe
Fast & fluent
Vectorise instead of apply, cut and qcut, ranking, method chaining, categories and speed.
- 39 Vectorise first: the speed laddercolumn maths · iterrows vs vectorised · .loc[mask, col] = … · the speed ladder 🔒 Subscribe
- 40 map and replace: look values upSeries.map(dict) · map(Series) · map(func) · replace · missing keys → NaN 🔒 Subscribe
- 41 apply: when you truly need itSeries.apply · DataFrame.apply(axis=1) · assign(lambda) · rewriting apply as vector maths 🔒 Subscribe
- 42 cut and qcut: numbers into bandspd.cut · bins · labels · right= · include_lowest · qcut · value_counts(sort=False) 🔒 Subscribe
- 43 Ranking: rank, ties and percentilesrank · method='average'/'min'/'dense'/'first' · ascending=False · pct=True · nlargest vs rank 🔒 Subscribe
- 44 Method chaining: one readable pipelinechains in ( … ) · assign(lambda) · query(@var) · pipe · sort_values · head 🔒 Subscribe
- 45 Categories: order and memoryastype('category') · CategoricalDtype(ordered=True) · sort by category order · cat.codes · groupby observed= 🔒 Subscribe
- 46 where, mask and clip: conditional values without loopsSeries.where · mask · clip · combine_first · fillna from another column 🔒 Subscribe
- 47 Refactor: from loops to one pipelineiterrows → column maths · apply → cut · chained indexing → .loc · list + one concat · groupby · .equals 🔒 Subscribe
Case files
End-to-end mini projects: load, inspect, clean, transform, group — and three insights.
- 48 Loading data: read_csv done rightread_csv · sep · parse_dates · na_values · dtype · usecols · to_csv 🔒 Subscribe
- 49 Case file: the café's month auditconcat · duplicated · str.strip/lower · to_datetime · fillna · groupby · value_counts 🔒 Subscribe
- 50 Case file: who are our regulars?str.zfill · merge(validate=, indicator=) · named agg · pd.cut · anti-join · Timestamp 🔒 Subscribe
- 51 Case file: are suppliers on time?drop_duplicates · str.strip · to_datetime · total_seconds · clip · resample · day_name 🔒 Subscribe
- 52 Case file: what reviews saystr.strip · map · str.count · str.extract · np.select · str.contains · findall · explode 🔒 Subscribe
- 53 Case file: the Monday reportmethod chain · pivot_table margins · merge validate · pct_change · share · rank · total check 🔒 Subscribe
Effective pandas
Nullable types, duplicates, crosstab and dummies, index and column tools, time zones, frequencies, plotting, debugging chains, export.
- 54 Nullable types: integers that keep their gapsInt64 · string · boolean · pd.NA · convert_dtypes 🔒 Subscribe
- 55 Duplicates: find them, decide, drop themduplicated(subset, keep) · drop_duplicates · keep='last'/False · index.duplicated · duplicate labels in maths 🔒 Subscribe
- 56 crosstab: counts and shares in one callpd.crosstab · normalize='index'/'columns'/'all' · margins · values + aggfunc 🔒 Subscribe
- 57 Dummy columns: one column per categorypd.get_dummies · prefix · drop_first · dtype=int · from_dummies · str.get_dummies 🔒 Subscribe
- 58 Index tools: reindex, sample, sort_index, filterreindex(fill_value) · sample(n, random_state) · sort_index · df.filter(like=, regex=) · rename_axis 🔒 Subscribe
- 59 Column housekeeping: flatten, rename, reorderflatten MultiIndex columns · set_axis · add_prefix/add_suffix · reorder with lists · .T 🔒 Subscribe
- 60 Time zones and epochsunit='s' · tz_localize · tz_convert · UTC · DST · nonexistent= / ambiguous= 🔒 Subscribe
- 61 Changing frequency: upsample, asfreq and anchored offsetsasfreq · resample('H').ffill / interpolate · 'W-MON' · 'MS' · pd.offsets 🔒 Subscribe
- 62 Plotting: see the shape of your data.plot.line · .plot.bar · .plot.hist · .plot.box · .plot.scatter · from groupby/pivot 🔒 Subscribe
- 63 Debugging chains: look inside, compare, assertpipe(peek) · assert · is_unique · .equals · pd.testing.assert_frame_equal 🔒 Subscribe
- 64 Export and present: JSON, SQL and a clean reportto_json(orient=) · read_json · to_sql/read_sql (sqlite3 :memory:) · to_string(formatters) · round 🔒 Subscribe