October 2017
Intermediate to advanced
532 pages
16h 10m
English
Passing a long list inside the indexing operator might cause readability issues. To help with this, you may save all your column names to a list variable first. The following code achieves the same result as step 1:
>>> cols = ['actor_1_name', 'actor_2_name', 'actor_3_name', 'director_name']>>> movie_actor_director = movie[cols]
One of the most common exceptions raised when working with pandas is KeyError. This error is mainly due to mistyping of a column or index name. This same error is raised whenever a multiple column selection is attempted without the use of a list:
>>> movie['actor_1_name', 'actor_2_name', 'actor_3_name', 'director_name']KeyError: ('actor_1_name', 'actor_2_name', 'actor_3_name', 'director_name')
This ...
Read now
Unlock full access