Can I select rows based on group size with pandas? Or do I have to use SQL?
I've made it work with records.groupby('product_name').filter(lambda x: len(x['url']) == 1). Note that simply using len(x) doesn't work. With a dataframe with more than two columns (which is probably most of the real-life dataframes), one has to specify a column for x: any column, except the one to group by with. Also, this code initially didn't work for me because my index on the dataframe was not unique. I'm not sure why this should interfere with the function of filtering, but it did. After reindexing the dataframe, I finally got it to work.
With pandas I can do grouping using df.groupby('product_name').size(). But if I'm only interested rows whose "product_name" is unique, i.e. those records with groupby.size equal to one, how can I filter the df to see only such rows? In other words, can I perform filtering on a database using pandas, based on the number of times an attribute occurs in the database? (I could do that with SQL alright.)