@@ -646,7 +646,7 @@ ten_lang = arranged_lang.head(10)
646
646
ten_lang
647
647
```
648
648
649
- ## Adding and modifying columns using ` assign `
649
+ ## Adding and modifying columns
650
650
651
651
``` {index} assign
652
652
```
@@ -663,7 +663,7 @@ column by the total Canadian population according to the 2016
663
663
census&mdash ; i.e., 35,151,728&mdash ; and multiply it by 100. We can perform
664
664
this computation using the code ` 100 * ten_lang["mother_tongue"] / canadian_population ` .
665
665
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
667
667
column to create (or old column to modify), then the assignment symbol ` = ` ,
668
668
and then the computation to store in that column. In this case, we will opt to
669
669
create a new column called ` mother_tongue_percent ` .
@@ -676,10 +676,18 @@ and do not affect how Python interprets the number. In other words,
676
676
although the latter is much clearer!
677
677
```
678
678
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
+
679
687
``` {code-cell} ipython3
680
688
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
683
691
```
684
692
685
693
The ` ten_lang_percent ` data frame shows that
0 commit comments