Skip to Content
Numerical Computing with Python
book

Numerical Computing with Python

by Pratap Dangeti, Allen Yu, Claire Chung, Aldrin Yim
December 2018
Beginner to intermediate
682 pages
18h 1m
English
Packt Publishing
Content preview from Numerical Computing with Python

There's more...

Another way to complete this recipe, beginning after step 2, is by directly assigning new columns from the sex_age column without using the split method. The assign method may be used to add these new columns dynamically:

>>> age_group = wl_melt.sex_age.str.extract('(\d{2}[-+](?:\d{2})?)',                                            expand=False)>>> sex = wl_melt.sex_age.str[0]>>> new_cols = {'Sex':sex,                 'Age Group': age_group}>>> wl_tidy2 = wl_melt.assign(**new_cols) \                      .drop('sex_age',axis='columns')>>> wl_tidy2.sort_index(axis=1).equals(wl_tidy.sort_index(axis=1))True

The Sex column is found in the exact same manner as done in step 5. Because we are not using split, the Age Group column must be extracted in a different manner. The extract method uses a complex regular ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Mastering Numerical Computing with NumPy

Mastering Numerical Computing with NumPy

Umit Mert Cakmak, Tiago Antao, Mert Cuhadaroglu

Publisher Resources

ISBN: 9781789953633OtherOtherErrata Page