Reader small image

You're reading from  Scientific Computing with Python - Second Edition

Product typeBook
Published inJul 2021
Reading LevelIntermediate
PublisherPackt
ISBN-139781838822323
Edition2nd Edition
Languages
Right arrow
Authors (3):
Claus Führer
Claus Führer
author image
Claus Führer

Claus Führer is a professor of scientific computations at Lund University, Sweden. He has an extensive teaching record that includes intensive programming courses in numerical analysis and engineering mathematics across various levels in many different countries and teaching environments. Claus also develops numerical software in research collaboration with industry and received Lund University's Faculty of Engineering Best Teacher Award in 2016.
Read more about Claus Führer

View More author details
Right arrow

10.2.1 Indexing rules

Similar to the way dictionaries use keys to address a value, pandas dataframes use row labels—the dataframe indexand column labels to access individual values:

AF.loc['R1', 'C2']      # this returns 2.0 

Or to generate a subframe:

AF.loc[['R1','R2'],['C1','C2']]

Resulting in:

   C1   C2
R1 1 2.0
R2 4 5.0

You can also address a complete row by using the index label:

AF.loc['R1']

This returns a pandas Series object:

C1    1.0
C2 2.0
C3 3.0
Name: R1, dtype: float64

If loc or iloc are called with list arguments or slices, the result is a dataframe.

In that way, an individual dataframe element can also be addressed as follows:

AF.loc['R1'].loc['C1']    # returns 1.0

An entire column is addressed directly as follows:

AF['C1']

This again returns a pandas Series object:

R1    1.0
R2 4.0
Name: C1, dtype: float64

Alternatively...

lock icon
The rest of the page is locked
Previous PageNext Page
You have been reading a chapter from
Scientific Computing with Python - Second Edition
Published in: Jul 2021Publisher: PacktISBN-13: 9781838822323

Authors (3)

author image
Claus Führer

Claus Führer is a professor of scientific computations at Lund University, Sweden. He has an extensive teaching record that includes intensive programming courses in numerical analysis and engineering mathematics across various levels in many different countries and teaching environments. Claus also develops numerical software in research collaboration with industry and received Lund University's Faculty of Engineering Best Teacher Award in 2016.
Read more about Claus Führer