Book Image

Learning Pandas

By : Michael Heydt
Book Image

Learning Pandas

By: Michael Heydt

Overview of this book

Table of Contents (19 chapters)
Learning pandas
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Selecting rows and values of a DataFrame using the index


Elements of an array or Series are selected using the [] operator. DataFrame overloads [] to select columns instead of rows, except for a specific case of slicing. Therefore, most operations of selection of one or more rows in a DataFrame, require alternate methods to using [].

Understanding this is important in pandas, as it is a common mistake is try and select rows using [] due to familiarity with other languages or data structures. When doing so, errors are often received, and can often be difficult to diagnose without realizing [] is working along a completely different axis than with a Series object.

Row selection using the index on a DataFrame then breaks down to the following general categories of operations:

  • Slicing using the [] operator

  • Label or location based lookup using .loc, .iloc, and .ix

  • Scalar lookup by label or location using .at and .iat

We will briefly examine each of these techniques and attributes. Remember, all of...