I am trying to figure out how to use a Locindexer object to select a subset of a DataFrame.
for instance
var = df.loc(df['rating'] == 4)
Returns as
pandas.core.indexing._LocIndexer
How to use LocIndexer to select a subset of my frame?
You call it a function. For indexing you use [].
df.loc[df['rating'] == 4]
will return a row / rows in which the column value is 4.
You should have no problem choosing a subset using the following code.
subset = df.loc[(df['rating'] == 4)]
Also, if you selected a line with:
you can get a special column of this row with
1.
df.loc[(df['rating'] == 4)]["column]
2.
subset["column"]
Source: https://habr.com/ru/post/1265758/More articles:Bidirectional LSTM for variable length sequences in Tensorflow - tensorflowTest Suite could not start TypeError: cannot read 'bind' property from undefined - javascriptHow can I parse YAML in a derived collection using YamlDotNet? - c #Several currencies - what to store and when to convert? - databaseSSRS - Excel data source error when deploying a report to a localhost report server - sql-server-2008Disabling the Visual Studio Hosting Process in Visual Studio Community 2017 - c #Disabling the Visual Studio Hosting Process in Visual Studio 2008 - visual-studio-2008boolean with groupby in pandas - pythonPython - AttributeError: object 'numpy.ndarray' does not have attribute 'append' - pythonOptional [Type [Foo]] raises a TypeError in Python 3.5.2 - pythonAll Articles