# df[ Name ].isin([ The target ]) For the row with target value in the current column, it will return True, There is no return False
df[df[ Name ].isin([ The target ])]
Practice cases
import pandas as pd
df_bom_data = pd.DataFrame([['A123',1200,5],
['B456',550,2],
['C437',500,10],
['D112',621,7],
['E211',755,11],
['F985',833,8]
],columns=['Material','Price','Quantity'])
df_material_shortage_data = pd.DataFrame([['A123','2022/6/21',100],
['B456','2022/6/22',120],
['C437','2022/6/23',250]
],columns=['Material','Schedule','LT'])
# select df_bom_data The table contains only df_material_shortage_data In the table Material The line record of
df_bom_data = df_bom_data[df_bom_data['Material'].isin(df_material_shortage_data['Material'])]
df_bom_data
df_material_shortage_data
df_bom_data( After processing )
# At the same time & Connect , Or | Connect
df[df[ Name ].isin([ The target ]) & df[ Name ].isin([ The target ])]
df[df[ Name ].isin([ The target ]) | df[ Name ].isin([ The target ])]
Practice cases
import pandas as pd
df = pd.DataFrame([['L123','A',0],
['L456','A',1],
['L437','C',0],
['L112','B',1],
['L211','A',0],
['L985','B',1]
],columns=['Material','Level','Passing'])
# Filter out the rows with target values in the specified columns
res1 = df[df['Level'].isin(['A','C']) & df['Passing'].isin([0])]
# Filter out at least one row with a target value
res2 = df[df['Level'].isin(['A','C']) | df['Passing'].isin([0])]
df
res1
res2
Practice cases
import pandas as pd
import numpy as np
df_bom_data = pd.DataFrame([['A123',1200,5],
['B456',np.nan,np.nan],
['C437',500,10]
],columns=['Material','Price','Quantity'])
df_material_shortage_data = pd.DataFrame([['A123','2022/6/21',100],
['B456','2022/6/22',120],
['C437','2022/6/23',250]
],columns=['Material','Schedule','LT'])
# select df_bom_data in 'Price' and 'Quantity' The values of both columns of fields are empty (nans) The line of
df_isnull_bom_data = df_bom_data[pd.isnull(df_bom_data[df_bom_data.columns.tolist()[1:]]).all(axis=1)]
# df_material_shortage_data Table delete all_isnull_df_bom_data In the table Material
df_material_shortage_data = df_material_shortage_data[~df_material_shortage_data['Material'].isin(df_isnull_bom_data['Material'])]
df_bom_data
df_material_shortage_data
df_isnull_bom_data
df_material_shortage_data( After processing )
Extended supplementary cases : Delete the row where the column is the specified value
import pandas as pd
df = pd.DataFrame([[0,1,2,3],
[4,5,6,7],
[8,9,10,11]
],columns=['A','B','C','D'])
# By taking a new value , Re assign values after data filtering , To delete row data whose column is the specified value
# Delete A The value in the column is 0 That line of records
df = df[df['A'] != 0]
df
df( After processing )