Pandas DataFrame.loc Method
Pandas DataFrame is a two-dimensional size-mutable, potentially heterogeneous tabular data structure with labeled axes (rows and columns). Arithmetic operations align on both row and column labels. It can be thought of as a dict-like container for Series objects. This is the primary data structure of the Pandas.
Pandas DataFrame loc Syntax
Pandas DataFrame.loc attribute access a group of rows and columns by label(s) or a boolean array in the given Pandas DataFrame.
Parameter : None
Returns : Scalar, Series, DataFrame
Pandas DataFrame loc Property
Example 1: Use DataFrame.loc attribute to access a particular cell in the given Pandas Dataframe using the index and column labels.
Now we will use DataFrame.loc attribute to return the value present in the ‘Name’ column corresponding to the ‘Row_2’ label.
Here, the DataFrame.loc attribute has successfully returned the value present at the desired location in the given DataFrame.
Example 2: Use DataFrame.loc attribute to return two of the column in the given Dataframe.
Now we will use DataFrame.loc attribute to return the values present in the ‘A’ and ‘D’ columns of the Dataframe.
As we can see in the output, the DataFrame.loc attribute has successfully returned the desired columns of the Dataframe.
Please Login to comment...