Filtering Pandas Dataframe using OR statement Filtering Pandas Dataframe using OR statement python python

Filtering Pandas Dataframe using OR statement


From the docs:

Another common operation is the use of boolean vectors to filter the data. The operators are: | for or, & for and, and ~ for not. These must be grouped by using parentheses.

http://pandas.pydata.org/pandas-docs/version/0.15.2/indexing.html#boolean-indexing

Try:

alldata_balance = alldata[(alldata[IBRD] !=0) | (alldata[IMF] !=0)]


You can do like below to achieve your result:

import seaborn as snsimport matplotlib.pyplot as pltimport pandas as pdimport numpy as np........#use filter with plot#orfg=sns.factorplot('Retailer country', data=df1[(df1['Retailer country']=='United States') | (df1['Retailer country']=='France')], kind='count')fg.set_xlabels('Retailer country')plt.show()#also#andfg=sns.factorplot('Retailer country', data=df1[(df1['Retailer country']=='United States') & (df1['Year']=='2013')], kind='count')fg.set_xlabels('Retailer country')plt.show()