Doubt on how lambda function works with filter

Course Name: Python for Trading: Basic, Section No: 8, Unit No: 19, Unit type: Notebook



Hi Team, 



My understanding is that when you apply Filter function, it refers to a set of columns in the dataframe.



For example, df.filter(items=['Col1','Col2'])



Now, when you involve a lambda function having parameter x along with a filter operation without any column specification, what is the value of x? 

The lambda function inside the filter() function takes a function and a list as arguments.



In the case groupby, the column of the dataframe you are using to group works as a list. Basically, x is the element of that column.



Try printing this piece of code and compare it with the original dataframe in the notebook. You will see the difference.



mp.groupby('MarketCap').filter(lambda x: len(x) > 3)



 

Thank you. Makes sense