Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

filter dataframe

tests_df[(tests_df['grade'] > 10)]
Comment

pandas filter dataframe

In [96]: df
Out[96]:
   A  B  C  D
a  1  4  9  1
b  4  5  0  2
c  5  5  1  0
d  1  3  9  6

In [99]: df[(df.A == 1) & (df.D == 6)]
Out[99]:
   A  B  C  D
d  1  3  9  6
Comment

filter pandas dataframe

1
2
3
4
# filter rows for year 2002 using  the boolean expression
>gapminder_2002 = gapminder[gapminder['year']==2002]
>print(gapminder_2002.shape)
(142, 6)
Comment

pandas dataframe filter

df = pd.DataFrame(np.array(([1, 2, 3], [4, 5, 6])),
...                   index=['mouse', 'rabbit'],
...                   columns=['one', 'two', 'three'])
>>> df
        one  two  three
mouse     1    2      3
rabbit    4    5      6

# select columns by name
df.filter(items=['one', 'three'])
         one  three
mouse     1      3
rabbit    4      6

# select columns by regular expression
df.filter(regex='e$', axis=1)
         one  three
mouse     1      3
rabbit    4      6

# select rows containing 'bbi'
df.filter(like='bbi', axis=0)
         one  two  three
rabbit    4    5      6
Comment

pandas column filter

filter = df['column']!= 0
df = df[filter]
Comment

Filter in pandas

#Filtering for SP state and price up or equal 115
sp_above_mean = df[(df['price'] >= 115) & (df['seller_state'] == 'SP')]
Comment

pandas filter column with or

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

pandas filter

# select columns by name
>>> df.filter(items=['one', 'three'])
         one  three
mouse     1      3
rabbit    4      6
Comment

filter pandas dataframe

1
2
3
4
# filter rows for year 2002 using  the boolean expression
>gapminder_2002 = gapminder[gapminder['year']==2002]
>print(gapminder_2002.shape)
(142, 6)
Comment

filter pandas dataframe

1
2
3
4
# filter rows for year 2002 using  the boolean expression
>gapminder_2002 = gapminder[gapminder['year']==2002]
>print(gapminder_2002.shape)
(142, 6)
Comment

pandas filter

df[(df['year'] > 2012) & (df['reports'] < 30)]
Comment

filter pandas dataframe

1
2
3
4
# filter rows for year 2002 using  the boolean expression
>gapminder_2002 = gapminder[gapminder['year']==2002]
>print(gapminder_2002.shape)
(142, 6)
Comment

filter pandas dataframe

1
2
3
4
# filter rows for year 2002 using  the boolean expression
>gapminder_2002 = gapminder[gapminder['year']==2002]
>print(gapminder_2002.shape)
(142, 6)
Comment

pandas filter

>continents = ['Asia','Africa', 'Americas', 'Europe']
>gapminder_Ocean = gapminder[~gapminder.continent.isin(continents)]
>gapminder_Ocean.shape 
(24,6)
Comment

pandas filter columns with IN

#To select rows whose column value is in list 
years = [1952, 2007]
gapminder.year.isin(years)
Comment

pandas filter

#To select rows whose column value is in list 
years = [1952, 2007]
gapminder.year.isin(years)
Comment

filter pandas dataframe

1
2
3
4
# filter rows for year 2002 using  the boolean expression
>gapminder_2002 = gapminder[gapminder['year']==2002]
>print(gapminder_2002.shape)
(142, 6)
Comment

filter pandas dataframe

1
2
3
4
# filter rows for year 2002 using  the boolean expression
>gapminder_2002 = gapminder[gapminder['year']==2002]
>print(gapminder_2002.shape)
(142, 6)
Comment

filter pandas dataframe

1
2
3
4
# filter rows for year 2002 using  the boolean expression
>gapminder_2002 = gapminder[gapminder['year']==2002]
>print(gapminder_2002.shape)
(142, 6)
Comment

PREVIOUS NEXT
Code Example
Python :: initialise a 2d array python 
Python :: How to construct a prefix sum array in python? 
Python :: python get the length of a list 
Python :: dataframe time index convert tz naive to tz aware 
Python :: python list remove at index 
Python :: uninstall python linux 
Python :: virtual env python 2 
Python :: query with condition django 
Python :: tkinter simple notification 
Python :: convert list to dataframe 
Python :: remove keys from array python 
Python :: How to wait a page is loaded in Python Selenium 
Python :: alpha beta pruning python code 
Python :: append python 
Python :: import file from parent directory python 
Python :: zero crossing rate python 
Python :: python substring in string 
Python :: python sort array of dictionary by value 
Python :: django install 
Python :: python search first occurrence in string 
Python :: how call module in the same directory 
Python :: how to get input with python 
Python :: python substring count 
Python :: how to get dictionary input from user in python 
Python :: python b before string 
Python :: embed image in html from python 
Python :: np.zeros 
Python :: startapp django 
Python :: python invert an array 
Python :: pyqt5 qtreewidgetitem enable drop drag 
ADD CONTENT
Topic
Content
Source link
Name
2+9 =