df.drop(df.loc[df['line_race']==0].index, inplace=True)
#to drop rows based on certain condition in a column
import pandas as pd
df = df[df['column']!=1]
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)
# date
#0 2015-01-01
#1 2015-02-01
#2 2015-03-01
#3 2015-04-01
#4 2015-05-01
#5 2015-06-01
df = df[~df['date'].isin(a)]
print(df)
# date
#2 2015-03-01
#3 2015-04-01
#4 2015-05-01
#5 2015-06-01
df = df[df.line_race != 0]
def filter_rows_by_values(df, col, values):
return df[~df[col].isin(values)]
In [215]:
df[df['entrytype'].apply(lambda x: str(x).isdigit())]
Out[215]:
entrytype
0 0
1 1
4 2
+---+--------------------------+----------------------------------+-----------+
| 1 | Sign up date | no_stores | no_unin_app no_stores_recei | ed_order |
+---+--------------------------+----------------------------------+-----------+
| 2 | 2020-04-01 | 1 | 0 | 0 |
| 3 | 2020-04-04 | 11 | 3 | 6 |
| 4 | 2020-04-13 | 8 | 1 | 4 |
+---+--------------------------+----------------------------------+-----------+
# create a new dataframe CONTAINING ONLY the rows, where the value
# of some_column = some_value
new_df = old_df.loc[old_df['some_column']=='some_value']
# create a new dataframe EXCLUDING the rows, where the value of
# some_column = some_value
new_df = old_df.loc[old_df['some_column']!='some_value']