python - How to check if there exists a row with a certain column value in pandas dataframe -


very new pandas.

is there way check given pandas dataframe, if there exists row column value. have column 'name' , need check name if exists.

and once this, need make similar query, bunch of values @ time. read there 'isin', i'm not sure how use it. need make query such rows have 'name' column matching of values in big array of names.

import numpy np import pandas pd df = pd.dataframe(data = np.arange(8).reshape(4,2), columns=['name', 'value']) 

result:

>>> df    name  value 0     0      1 1     2      3 2     4      5 3     6      7 >>> any(df.name == 4) true >>> any(df.name == 5) false 

second part:

my_data = np.arange(8).reshape(4,2) my_data[0,0] = 4  df = pd.dataframe(data = my_data, columns=['name', 'value']) 

result:

>>> df.loc[df.name == 4]    name  value 0     4      1 2     4      5 

update:

my_data = np.arange(8).reshape(4,2) my_data[0,0] = 4  df = pd.dataframe(data = my_data, index=['a', 'b', 'c', 'd'], columns=['name', 'value']) 

result:

>>> df.loc[df.name == 4]  # gives relevant rows    name  value     4      1 c     4      5   >>> df.loc[df.name == 4].index  # give "row names" of relevant rows index([u'a', u'c'], dtype=object) 

Comments

Popular posts from this blog

PHPMotion implementation - URL based videos (Hosted on separate location) -

javascript - Using Windows Media Player as video fallback for video tag -

c# - Unity IoC Lifetime per HttpRequest for UserStore -