Accessing attributes using the dot operator

To access a single entity (a column, value, or item), the square bracket operator can be replaced by the dot operator. Let's subset colA in the DataFrame using the dot (.) operator:

df.colA

This results in the following output:

Slicing a column with the dot operator

By using two dot operators in a chain, an individual element can be accessed: 

In: df.colA.R3
Out: -2.089066

This is also applicable to Panels and Series. However, unlike the square bracket operator in Series, the positional index cannot be used here. For the dot operator to be used, the row labels or column labels must have valid names. A valid Python identifier must follow the following lexical convention:

identifier::= (letter|"_") (letter | digit | "_")*
Thus, a valid Python identifier cannot contain a space. See the Python Lexical Analysis documents for more details at http://docs.python.org/2.7/reference/lexical_analysis.html#identifiers.

Using the dot operator, the values of existing columns can be changed. However, new columns cannot be created.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset