Answers for "filter specific rows in pandas based on values"

2

pandas filter rows by value in list

df.loc[df['col name'].isin(ls_conditions)]
Posted by: Guest on May-20-2020
0

filter one dataframe by another

df1 = pd.DataFrame({'c': ['A', 'A', 'B', 'C', 'C'],
                    'k': [1, 2, 2, 2, 2],
                    'l': ['a', 'b', 'a', 'a', 'd']})
df2 = pd.DataFrame({'c': ['A', 'C'],
                    'l': ['b', 'a']})
keys = list(df2.columns.values)
i1 = df1.set_index(keys).index
i2 = df2.set_index(keys).index
df1[~i1.isin(i2)]
Posted by: Guest on August-10-2020

Code answers related to "filter specific rows in pandas based on values"

Python Answers by Framework

Browse Popular Code Answers by Language