Skip to content

Commit cef9994

Browse files
committed
Formatting fixes and updates to Week 2
1 parent cd86810 commit cef9994

2 files changed

Lines changed: 55 additions & 26 deletions

File tree

‎README.md‎

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1444,24 +1444,34 @@ This is most common way to get data
14441444
print(subset.max(axis=None))
14451445
```
14461446
1447-
\*\*\*( Optional) Get x/y labels for the cell that matches a criterion
1447+
### (Optional) How to get the x and y labels for the cell that matches a criterion
14481448
1449-
``` python
1450-
# Which values match the criterion?
1451-
subset == subset.max().max()
1449+
1. Doing it the hard way
14521450
1453-
# Return value at position, code all other cells as NA
1454-
val = subset[subset == subset.max().max()]
1451+
``` python
1452+
# Which values match the criterion?
1453+
subset == subset.max().max()
14551454
1456-
# Drop rows where all values are NA, then drop columns where values are NA
1457-
val.dropna(how="all").dropna(axis=1)
1455+
# Return value at position, code all other cells as NA
1456+
val = subset[subset == subset.max().max()]
14581457
1459-
# Putting it all together: Get index label and column label for last remaining cell
1460-
names = val.dropna(how="all").dropna(axis=1)
1458+
# Drop rows where all values are NA, then drop columns where values are NA
1459+
val.dropna(how="all").dropna(axis=1)
14611460
1462-
print(names.index[0])
1463-
print(names.columns[0])
1464-
```
1461+
# Putting it all together: Get index label and column label for last remaining cell
1462+
names = val.dropna(how="all").dropna(axis=1)
1463+
1464+
print(names.index[0])
1465+
print(names.columns[0])
1466+
```
1467+
1468+
2. Frequently there will be a built-in method that solves the same problem
1469+
1470+
``` python
1471+
df.idxmax()
1472+
df.unique()
1473+
df.nunique()
1474+
```
14651475
14661476
### (Optional) Filter on label properties
14671477

‎README.org‎

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,17 @@
66
#+AUTHOR: Derek Devnich
77

88
* COMMENT Notes
9+
** Teaching notes from Fall 2026 UC Carpentry
10+
1. Terminal install is a problem
11+
- Need easy backup
12+
2. Get data from Python?
13+
- http fetch
14+
- short url for zip
15+
3. Review SQL-like materials in Week 2
16+
4. Excel import: https://openpyxl.readthedocs.io/en/stable/
17+
5. https://python-graph-gallery.com
18+
6. https://github.com/trevismd/statannotations
19+
920
** Drops down to NumPy for numeric calculations, obviating any Pandas issues
1021
#+BEGIN_SRC python
1122
def zScoreCalc (filename, index_colum_name = None):
@@ -1281,23 +1292,31 @@ This is most common way to get data
12811292
print(subset.max(axis=None))
12821293
#+END_SRC
12831294

1284-
***( Optional) Get x/y labels for the cell that matches a criterion
1285-
#+begin_src python
1286-
# Which values match the criterion?
1287-
subset == subset.max().max()
1295+
*** (Optional) How to get the x and y labels for the cell that matches a criterion
1296+
1. Doing it the hard way
1297+
#+begin_src python
1298+
# Which values match the criterion?
1299+
subset == subset.max().max()
1300+
1301+
# Return value at position, code all other cells as NA
1302+
val = subset[subset == subset.max().max()]
12881303

1289-
# Return value at position, code all other cells as NA
1290-
val = subset[subset == subset.max().max()]
1304+
# Drop rows where all values are NA, then drop columns where values are NA
1305+
val.dropna(how="all").dropna(axis=1)
12911306

1292-
# Drop rows where all values are NA, then drop columns where values are NA
1293-
val.dropna(how="all").dropna(axis=1)
1307+
# Putting it all together: Get index label and column label for last remaining cell
1308+
names = val.dropna(how="all").dropna(axis=1)
12941309

1295-
# Putting it all together: Get index label and column label for last remaining cell
1296-
names = val.dropna(how="all").dropna(axis=1)
1310+
print(names.index[0])
1311+
print(names.columns[0])
1312+
#+end_src
12971313

1298-
print(names.index[0])
1299-
print(names.columns[0])
1300-
#+end_src
1314+
2. Frequently there will be a built-in method that solves the same problem
1315+
#+begin_src python
1316+
df.idxmax()
1317+
df.unique()
1318+
df.nunique()
1319+
#+end_src
13011320

13021321
*** (Optional) Filter on label properties
13031322
1. ~.filter()~ always returns the same type as the original item, whereas ~.loc~ and ~.iloc~ might return a data frame or a series.

0 commit comments

Comments
 (0)