1

I'm trying to understand pandas, using it for data processing. I come from a C# world where all data filtering and manipulation is done through LINQ and anonymous functions. I've learned that with a data frame I can do something like this.

filtereddf = df[df['column'] == foo]

Which would return to me all the dataframe rows, where the column value is foo. What I'm trying to understand is, how is df['column'] == foo interpreted as an indexer? Is it treated as an anonymous function that is run every row, with "df" being a stand in for the row value?

Additionally, if I do df[df['column'] == foo, 'bar'] I get a series of the bar column from rows where column is equal to foo. Is the logic used in interpreting df['column'] == foo the same here, instead of returning a dataframe with a list of rows, it returns a list of values representing bar?

Sidney
  • 624
  • 7
  • 20
  • this should help: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#boolean-indexing – It_is_Chris Oct 16 '20 at 16:51
  • Does this answer your question? [Understanding \_\_getitem\_\_ method](https://stackoverflow.com/questions/43627405/understanding-getitem-method). Check out Cong's answer. Basically `[]` just calls this `__getitem__` method. – noah Oct 16 '20 at 16:52

0 Answers0