You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit b9ebc1b
Browse filesBrowse the repository at this point in the historyBrowse files
Copy file name to clipboardExpand all lines: apps/web/src/App.tsx
+12-1Lines changed: 12 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -14,7 +14,7 @@ import type { editor as MonacoEditor } from 'monaco-editor';
14
14
constDEFAULT_MARKDOWN=`## How to use this notebook
15
15
16
16
- **Markdown cell (this cell):** Double-tap or double-click to edit. Use **Shift+Enter** or the **Render** button to see the rendered version and (with Shift+Enter) move to the code cell.
17
-
- **Code cell:** Write Python using \`Table\` and \`make_array\` from the \`datascience\` library. Press **Run** or **Ctrl+Enter** (**Cmd+Enter** on Mac) to execute. The right panel shows step-by-step table operations.
17
+
- **Code cell:** Write Python using the \`datascience\` library. Press **Run** or **Ctrl+Enter** (**Cmd+Enter** on Mac) to execute. The right panel shows step-by-step table operations.
18
18
- **Visualization:** After running, use the arrows to step through operations and **Export** to save as PDF or **Share** to copy a link.`;
19
19
20
20
constDEFAULT_CODE=`from datascience import *
@@ -407,10 +407,20 @@ function App() {
407
407
})();
408
408
},[isRunning]);
409
409
410
+
// Back to the starter notebook (what you see on first visit)
description: 'Choose specific columns from a table',
22
+
markdown: `## Selecting columns
23
+
24
+
\`select\` builds a new table containing only the columns you name, in the order you name them. The original table is left untouched. That is true of every \`Table\` method.
25
+
26
+
Step through the visualization and notice that the number of rows never changes; only the columns do.`,
21
27
category: 'basics',
22
28
operations: ['select'],
23
29
code: `from datascience import *
@@ -45,6 +51,11 @@ result.show()
45
51
id: 'filter-rows',
46
52
title: 'Filtering Rows',
47
53
description: 'Keep only rows that match a condition',
54
+
markdown: `## Filtering rows with \`where\`
55
+
56
+
\`where(column, value)\` keeps only the rows whose value in that column matches. Here we keep the CS majors.
57
+
58
+
As you step through, watch each row get checked against the condition: kept rows are highlighted, and the ones that don't match are struck through before they disappear from the result.`,
48
59
category: 'filtering',
49
60
operations: ['where'],
50
61
code: `from datascience import *
@@ -71,6 +82,11 @@ cs_students.show()
71
82
id: 'sort-values',
72
83
title: 'Sorting by Values',
73
84
description: 'Order rows by a column',
85
+
markdown: `## Sorting rows
86
+
87
+
\`sort(column)\` orders the rows by a column, smallest first. Passing \`descending=True\` flips that, so the highest GPA comes out on top.
88
+
89
+
Every row survives a sort. Only their order changes. Watch the rows move in the step-through.`,
74
90
category: 'sorting',
75
91
operations: ['sort'],
76
92
code: `from datascience import *
@@ -96,6 +112,11 @@ sorted_students.show()
96
112
id: 'add-column',
97
113
title: 'Adding a Column',
98
114
description: 'Add a new column to the table',
115
+
markdown: `## Adding a column
116
+
117
+
\`with_column(label, values)\` returns a copy of the table with one more column. The array of values must have exactly one entry per row, in row order.
118
+
119
+
Here \`grades\` is an array we build first with \`make_array\`, then attach. Watch the new column appear on the right of the result.`,
99
120
category: 'transforming',
100
121
operations: ['with_column'],
101
122
code: `from datascience import *
@@ -122,6 +143,11 @@ result.show()
122
143
id: 'drop-column',
123
144
title: 'Dropping Columns',
124
145
description: 'Remove columns from a table',
146
+
markdown: `## Dropping columns
147
+
148
+
\`drop\` is the mirror image of \`select\`: you name the columns you want to get rid of, and everything else stays.
149
+
150
+
Use it when a table has many columns and it is easier to say what you don't need.`,
125
151
category: 'basics',
126
152
operations: ['drop'],
127
153
code: `from datascience import *
@@ -149,6 +175,11 @@ result.show()
149
175
id: 'group-aggregate',
150
176
title: 'Grouping and Aggregating',
151
177
description: 'Group rows and compute statistics',
178
+
markdown: `## Grouping and aggregating
179
+
180
+
\`group(column, function)\` collects the rows that share a value in the column, then applies the function to each group's values. With \`sum\`, every product ends up with the total of its amounts.
181
+
182
+
Step through it: first the rows are gathered into groups, then the values in each group are collapsed into one number. Notice the new column is named \`Amount sum\`.`,
152
183
category: 'grouping',
153
184
operations: ['group'],
154
185
code: `from datascience import *
@@ -175,6 +206,11 @@ totals.show()
175
206
id: 'join-tables',
176
207
title: 'Joining Tables',
177
208
description: 'Combine two tables on a common column',
209
+
markdown: `## Joining two tables
210
+
211
+
\`join(column, other_table)\` matches rows from two tables that share a value in the named column and lines them up side by side.
212
+
213
+
Here both tables have an \`ID\` column. Watch the second table appear under the first, with matching keys highlighted as each row is paired up.`,
178
214
category: 'joining',
179
215
operations: ['join'],
180
216
code: `from datascience import *
@@ -210,6 +246,11 @@ result.show()
210
246
id: 'chain-operations',
211
247
title: 'Chaining Operations',
212
248
description: 'Combine multiple operations in sequence',
249
+
markdown: `## Chaining operations
250
+
251
+
Because every \`Table\` method returns a new table, you can call another method on the result right away. Wrapping the expression in parentheses lets you put each step on its own line.
252
+
253
+
Read it top to bottom: keep the CS majors, keep only name and GPA, then sort. The visualization shows one step per method call.`,
213
254
category: 'basics',
214
255
operations: ['select','where','sort'],
215
256
code: `from datascience import *
@@ -240,6 +281,11 @@ result.show()
240
281
id: 'multiple-filters',
241
282
title: 'Multiple Filters',
242
283
description: 'Apply multiple where conditions',
284
+
markdown: `## Filtering twice
285
+
286
+
A second \`where\` on the result of the first narrows things down further. \`are.above(3.5)\` is a *predicate*, a reusable condition, from the \`are\` collection.
287
+
288
+
Compare the two filter steps: the first checks the Major column, the second checks GPA against a threshold.`,
243
289
category: 'filtering',
244
290
operations: ['where'],
245
291
code: `from datascience import *
@@ -274,6 +320,11 @@ high_gpa.show()
274
320
id: 'pivot-table',
275
321
title: 'Pivot Tables',
276
322
description: 'Reshape data with pivot operations',
323
+
markdown: `## Pivoting
324
+
325
+
\`pivot(columns, rows, values, function)\` turns one column's values into column headers and another's into row labels, then fills each cell by aggregating the \`values\` column.
326
+
327
+
Here every Product becomes a column and every Region a row, and each cell is the sum of Sales for that pair. Step through to see the source rows feed each cell.`,
277
328
category: 'transforming',
278
329
operations: ['pivot'],
279
330
code: `from datascience import *
@@ -300,6 +351,11 @@ pivoted.show()
300
351
id: 'group-multiple',
301
352
title: 'Group with Multiple Aggregates',
302
353
description: 'Group by column and compute multiple statistics',
354
+
markdown: `## Different aggregates on the same groups
355
+
356
+
The function you pass to \`group\` decides what each group collapses to. \`np.mean\` gives the average score per major; \`max\` gives the highest.
357
+
358
+
The groups are identical in both calls. Only the number in the second column changes, and so does its name: \`Score mean\` versus \`Score max\`.`,
303
359
category: 'grouping',
304
360
operations: ['group'],
305
361
code: `from datascience import *
@@ -332,6 +388,11 @@ max_scores.show()
332
388
id: 'join-multiple-keys',
333
389
title: 'Joining on Multiple Keys',
334
390
description: 'Join tables with multiple matching columns',
391
+
markdown: `## Joining on an ID
392
+
393
+
\`StudentID\` is the key that links a student's record to their enrollment. \`join\` pairs each row in \`students\` with the row in \`enrollment\` that has the same ID.
394
+
395
+
Watch the keys get matched one at a time, and notice the joined table keeps the columns from both.`,
This is the shape of most real analyses: filter down to the rows you care about, select the useful columns, group to summarise, and sort to rank.
435
+
436
+
Watch how the table changes character at each step, from individual transactions to one row per product. The sort uses \`Amount sum\`, the column that \`group\` created.`,
description: 'Select a specific number of rows from a table',
469
+
markdown: `## Taking rows by position
470
+
471
+
\`take(n)\` returns the first \`n\` rows. You can also pass a specific row number, or a range of them, using \`take(np.arange(start, stop))\`.
472
+
473
+
Row positions start at 0. Watch the first three rows get picked out and the rest fall away.`,
403
474
category: 'basics',
404
475
operations: ['take'],
405
476
code: `from datascience import *
@@ -426,6 +497,11 @@ sample.show()
426
497
id: 'pivot-complex',
427
498
title: 'Complex Pivot Operation',
428
499
description: 'Reshape data with multiple dimensions',
500
+
markdown: `## Pivoting scores
501
+
502
+
Each student took each subject once, so the pivot has one row per student and one column per subject, and each cell holds that student's score.
503
+
504
+
Step through and check that every (student, subject) pair from the original table lands in exactly one cell.`,
429
505
category: 'transforming',
430
506
operations: ['pivot'],
431
507
code: `from datascience import *
@@ -452,6 +528,11 @@ pivoted.show()
452
528
id: 'group-with-aggregate',
453
529
title: 'Group with Custom Aggregate',
454
530
description: 'Group data and apply custom aggregation functions',
531
+
markdown: `## Total versus average
532
+
533
+
Grouping by Region with \`sum\` gives each region's total; grouping with \`np.mean\` gives its average. The groups are the same, the summary differs.
534
+
535
+
Notice the group step happens first in both calls, and the aggregation happens after.`,
455
536
category: 'grouping',
456
537
operations: ['group'],
457
538
code: `from datascience import *
@@ -484,6 +565,11 @@ avg_by_region.show()
484
565
id: 'multi-step-analysis',
485
566
title: 'Multi-Step Data Analysis',
486
567
description: 'Complete workflow: filter, group, sort, and select',
568
+
markdown: `## Filter, group, sort, select
569
+
570
+
A four-step analysis, one method at a time. Keep employees with at least three years (\`are.above_or_equal_to\`), average each department's scores, rank the departments, then keep just the two columns worth reporting.
571
+
572
+
Watch the \`Years\` column disappear after the group step: once rows are collapsed into groups, only the aggregated columns remain.`,
0 commit comments