Unit 36Transforming Data

Now you’re ready to have a look at the pandas “powerhouse”: vectorized arithmetic, logical operations, and other data transformation mechanisms.

Arithmetic Operations

pandas supports the four arithmetic operations (addition, subtraction, multiplication, and division) and numpy universal functions (or ufuncs, which were explained here). The operators and functions can be used to combine frames of the same size and structure, frame columns and series, and series of the same size.

We’re finally in the position to correct the “Total” column of the alco frame:

 alco[​"Total"​] = alco.Wine + alco.Spirits + alco.Beer
 alco.head()
=>  Beer Wine Spirits Total
=> State Year
=> Alabama 1977 0.99 0.13 0.84 1.96
=>  1978 ...

Get Data Science Essentials in Python now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.