What exactly is pandas doing for this data slicing under the hood?

252 Views Asked by At

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?

0

There are 0 best solutions below