Pandas Joins, MultiIndex, Grouping and Reshaping | ISOM5650 2.3
Neuron UCI
0:00 / 0:00
Pandas Joins, MultiIndex, Grouping and Reshaping | ISOM5650 2.3
4 просмотра · 5 дней назад
Neuron UCI
21 подписчик
4 просмотра · 5 дней назад
Assemble tables with concat and joins, inspect matching multiplicity, and manipulate a named MultiIndex. Trace set_index, reset_index, sort_index, xs and IndexSlice, then compare stack, unstack, pivot, melt, pivot_table and crosstab.
Learn with Professor Xuhu Wan in ISOM5650: Learning Statistics With Python. Follow real Python runs, changed inputs and interactive illustrations. First appearances of code are explained line by line; later examples focus on the new idea.
RESOURCES
Video + interactive slides: https://statpython.pages.dev/lesson.h...
Lecture slides: https://statpython.pages.dev/section-...
Course book: https://statpython-book.pages.dev/top...
Course playlist: • learnStatisticswithPython
CHAPTERS
00:00 Grouped Tables, Joins and Reshaping
00:31 Grouped Tables, Joins and Reshaping
01:03 Grouped aggregation, transform and filter
01:29 groupby: one number per group
02:15 Several aggregations at once, your own functions, named columns
03:07 transform: same shape as the input
03:52 filter: keep whole groups that pass a test
04:57 Your turn: interquartile range by weekday
06:20 Weekly resampling groups clock time, not every seventh row
07:08 Joins on multiple columns and validation
07:59 A second frame: Times university rankings 2011–2016
08:53 Joins: inner, left, outer — who survives?
09:51 Your turn: count the universities that dropped out
11:18 One research row means one security and one date
12:02 Join on both stock and date and inspect unmatched rows
13:13 Combine tables: matching columns or concatenating axes
13:41 pd.concat: side by side, or on top
14:46 Stop a join when a stock/date pair is repeated
15:59 Your turn: assemble a pair and correlate it
17:24 MultiIndex and long/wide representations
17:50 A MultiIndex identifies each row using two index levels
18:17 Six rows for the index examples
18:59 Set two columns as the index
19:59 Sort a MultiIndex before selecting a range
20:58 Move one index level into a column
21:58 Add a column to the existing index
23:03 Restore all index levels as columns
24:03 Select one stock using the outer index level
24:59 Select one date using a named index level
25:58 Select one index pair or one cell
26:52 What pd.IndexSlice means
27:18 Use IndexSlice for a range or all stocks
28:23 Swap index levels, then sort the new order
29:16 Apply the index operations to the full research panel
30:20 Reshape the return panel without aggregating repeated stock/date pairs
30:48 Run unstack and compare the Series with the table
31:47 Stack columns into an inner index level
32:34 Missing combinations after unstack
33:38 Transpose swaps the entire row and column axes
34:36 Verify the full long–wide–long round trip
35:48 melt, pivot and pivot_table: the structural difference
36:17 pivot: choose the row index, column headings and values
37:18 melt: retain identifiers and turn value columns into rows
38:25 pivot_table: two grouping columns become rows × columns
38:53 Run pivot_table with explicit keyword arguments
39:57 The same table by groupby + unstack
40:24 Inspect the grouped Series before unstacking it
41:27 Apply the comparison to four countries and six years
42:56 melt and pivot on the five-stock price panel
44:07 Inventory prices by release year: pivot_table and crosstab
45:08 Inventory counts: unstack either named level
46:09 Inventory prices: stack flag columns into the index
47:11 Inventory prices: transpose the year and flag axes
48:10 pd.cut: assign values to intervals
49:02 Plotting a frame
49:48 Your turn: citations vs rank, top 100 of 2016