July 2019
Beginner to intermediate
740 pages
16h 52m
English
First, we will cover adding new rows and columns, and later we will delete them. Creating new columns can be achieved in the same fashion as variable assignment. For example, we can create a column of ones for our data:
>>> df['ones'] = 1>>> df.head()
The new column is created to the right of the original columns, with a value of 1 for every row:
| alert | mag | magType | place | time | title | tsunami | ones | |
|---|---|---|---|---|---|---|---|---|
| 0 | NaN | 1.35 | ml | 9km NE of Aguanga, CA | 1539475168010 | M 1.4 - 9km NE of Aguanga, CA | 0 | 1 |
| 1 | NaN | 1.29 | ml | 9km NE of Aguanga, CA | 1539475129610 | M 1.3 - 9km NE of Aguanga, CA | 0 | 1 |
| 2 | NaN | 3.42 | ml | 8km NE of Aguanga, CA | 1539475062610 | M 3.4 - 8km NE of Aguanga, CA | 0 | 1 |
| 3 | NaN | 0.44 | ml | 9km NE of Aguanga, CA | 1539474978070 | M 0.4 - 9km NE of ... |
Read now
Unlock full access