Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Hi guys, since its so quiet here 1

Status
Not open for further replies.

kingz2000

Programmer
May 28, 2002
304
DE
Hi guys,

since its so quiet here ,let me throw in another easy one. The problem is, that I'm so used toSQL and using "Where"..So here goes..

df['artist'].value_counts().reset_index()

gives me a select count...

now how I can add a condition to only list those above a certain number, say 3?

I tried this...

df.groupby('artist').count()>3

..which just gave me my list with true and false on each column.

Thanks in advance
 
yes, df is the general short term for any panda dataframe
 
kingz2000,
it would be helpful if you could post how your data looks like.
 
I tried this:
first I created this data frame from a list of items
Code:
>>> my_list = ['foo', 'bar', 'baz', 'foo', 'bar', 'foo', 'bar', 'foo']

>>> my_df=pd.DataFrame({"item" : my_list})

>>> my_df
  item
0  foo
1  bar
2  baz
3  foo
4  bar
5  foo
6  bar
7  foo

Now I can get a list of items which occurs more than once in these steps:
Code:
>>> my_df["item"].value_counts()>1
foo     True
bar     True
baz    False
Name: item, dtype: bool

>>> my_df.loc[(my_df["item"].value_counts()>1).values]
  item
0  foo
1  bar

>>> list((my_df.loc[(my_df["item"].value_counts()>1).values])["item"])
['foo', 'bar']
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top