delete rows based on condition python code example
Example 1: 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 2: delete rows based on condition python
df = df.drop(df[df.score < 50].index)
Example 3: delete rows based on condition python
df.drop(df[df.score < 50].index, inplace=True)