Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pandas: How to use LocIndexer?

Tags:

python

pandas

I am trying to figure out how to use a Locindexer object to select a subset of a dataframe.

For example

var = df.loc(df['rating'] == 4)

Returns as

pandas.core.indexing._LocIndexer

How do I use a LocIndexer to select the a subset of my dataframe?

like image 770
Liam Pieri Avatar asked Mar 22 '17 00:03

Liam Pieri


1 Answers

You are calling it as a function. For indexing, you use [].

df.loc[df['rating'] == 4]

would return the row/rows in which value of column rating is 4.

like image 172
Vaishali Avatar answered Oct 05 '22 04:10

Vaishali