drop rows with column value pandas code example
Example 1: python: remove specific values in a dataframe
df.drop(df.index[df['myvar'] == 'specific_name'], inplace = True)
Example 2: pandas drop rows with value in list
import pandas as pd
a = ['2015-01-01' , '2015-02-01']
df = pd.DataFrame(data={'date':['2015-01-01' , '2015-02-01', '2015-03-01' , '2015-04-01', '2015-05-01' , '2015-06-01']})
print(df)
df = df[~df['date'].isin(a)]
print(df)
Example 3: delete rows with value in column pandas
df = df[df.line_race != 0]
Example 4: drop row pandas column value not a number
In [215]:
df[df['entrytype'].apply(lambda x: str(x).isdigit())]
Out[215]:
entrytype
0 0
1 1
4 2