Mar-28-2017, 07:38 PM
You cant use your value_counts() serie to index your dataframe - value_counts returns serie with length equal to a number of unique items in column "title", different from length of original dataframe.
You need to use something more complicated, like use value counts to get unique items (counted items form index of value_counts serie) and after that use dataframe selection with .isin() function.
Simple example with fictional data;
You need to use something more complicated, like use value counts to get unique items (counted items form index of value_counts serie) and after that use dataframe selection with .isin() function.
Simple example with fictional data;
In [27]: df = pd.DataFrame({'title': ['steward', 'chef', 'cook', 'steward', 'cook'], 'value':[13,34,23,30,17]}) In [28]: counts = df.title.value_counts() In [29]: counts Out[29]: steward 2 cook 2 chef 1 Name: title, dtype: int64 In [30]: counts[counts==1] Out[30]: chef 1 Name: title, dtype: int64 In [31]: df[df.title.isin(counts[counts==1].index)] Out[31]: title value 1 chef 34