Skip to content

Commit 1b39bc6

Browse files
remove assign in ch1
1 parent 10b0f34 commit 1b39bc6

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

source/intro.md

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -646,7 +646,7 @@ ten_lang = arranged_lang.head(10)
646646
ten_lang
647647
```
648648

649-
## Adding and modifying columns using `assign`
649+
## Adding and modifying columns
650650

651651
```{index} assign
652652
```
@@ -663,7 +663,7 @@ column by the total Canadian population according to the 2016
663663
census—i.e., 35,151,728—and multiply it by 100. We can perform
664664
this computation using the code `100 * ten_lang["mother_tongue"] / canadian_population`.
665665
Then to store the result in a new column (or
666-
overwrite an existing column), we use the `assign` method. We specify the name of the new
666+
overwrite an existing column), we specify the name of the new
667667
column to create (or old column to modify), then the assignment symbol `=`,
668668
and then the computation to store in that column. In this case, we will opt to
669669
create a new column called `mother_tongue_percent`.
@@ -676,10 +676,18 @@ and do not affect how Python interprets the number. In other words,
676676
although the latter is much clearer!
677677
```
678678

679+
```{code-cell} ipython3
680+
:tags: [remove-cell]
681+
# disable setting with copy warning
682+
# it's not important for this chapter and just distracting
683+
# only occurs here because we did a much earlier .loc operation that is being picked up below by the coln assignment
684+
pd.options.mode.chained_assignment = None
685+
```
686+
679687
```{code-cell} ipython3
680688
canadian_population = 35_151_728
681-
ten_lang_percent = ten_lang.assign(mother_tongue_percent=100 * ten_lang["mother_tongue"] / canadian_population)
682-
ten_lang_percent
689+
ten_lang["mother_tongue_percent"] = 100 * ten_lang["mother_tongue"] / canadian_population
690+
ten_lang
683691
```
684692

685693
The `ten_lang_percent` data frame shows that

0 commit comments

Comments
 (0)