Pandasmonium: Day 3
2025-10-22
df, making the “name” the column header?line1 = "English German Spanish French"
line2 = "dog Hund perro chien"
line3 = "cat Katze gato chat"
line4 = "house Haus casa maison"DataFrame, with the languages in line1 serving as the column headers.dfWe’ve seen that you can combine two dfs together with pd.concat()
There’s a simpler way, though, to add a .Series() that should remind you of lists and dicts:
.Series() with .drop().drop([index]).rename() method.reset_index().reset_index(drop=True)Or convert a .Series() to the index
df you built for the Review Activitydf by:
df intact, but drop the index altogetherBob column into the index.pddfs that are aligned by indexNaN
.add() to total all of the reflexes in the df by language
{python}
reflexes_verb = pd.Series(
{"Latin": 8, "Greek": 10, "Sanskrit": 12, "Old English": 6}
)
reflexes_noun = pd.Series(
{"Latin": 5, "Greek": 7, "Gothic": 4, "Old Church Slavonic": 3}
)
combined = pd.DataFrame({"verb": reflexes_verb, "noun": reflexes_noun})
combined
column_totals = combined.sum(axis=0)
print(column_totals)| Chapter | s | z | t | k | m | n |
|---|---|---|---|---|---|---|
| 1 | 35 | 20 | 50 | 42 | 18 | 22 |
| 2 | 28 | 25 | 40 | 35 | 12 | 20 |
| 3 | 40 | 18 | 53 | 48 | 17 | 19 |
.add(), tally up how many Cs are in each chapter.| Chapter | s | z | t | k | m | n |
|---|---|---|---|---|---|---|
| 1 | 35 | 20 | 50 | 42 | 18 | 22 |
| 2 | 28 | 25 | 40 | 35 | 12 | 20 |
| 3 | 40 | 18 | 53 | 48 | 17 | 19 |
.sum() and .add(), identify the total number of fricatives.