Learn Before
Concept

Direct Indexing in Pandas Data Frame

Pandas has 4 functions that allow for direct access and modification of the underlying values of the data: python df.iloc[3] This will select the data in column 3. We can also use integer slicing, similar to numpy to access more specific values, python df.iloc[3:5, 0:2]

We can also access using labels, python df.loc[dates[0]] or python df.loc[:, ["A", "B"]].

Data can also be accessed using boolean values, python df[df > 0] will select all values greater than 0. python df[df["A"] > 0] will select all values in column labeled "A" with values greater than 0.

We can also use df.at and df.iat to access data directly. Usage is very similar to .loc and .iloc. All data accesses are pass by references, which means that modifications made using python df["A"] = 0 will result in setting all values to 0.

0

0

Updated 2021-05-28

Tags

Python Programming Language

Data Science