How do I make this code more efficient? I am trying to implement the below-given logic on a much bigger data frame of 100 columns. The idea is to take the required keywords and perform further filtering like filtered_df = df[result]
search_list= ['A','B']
df_column_names=['Apple','Airplanne','Banana','Ball','Bat','Cat','Champ','Dog','OX','Zebra']
result=[]
for search_string in search_list:
for column_name in df_column_names:
if search_string in column_name:
result.append(column_name)
result =['Apple', 'Airplanne', 'Banana', 'Ball', 'Bat']
Get the result and perform filtering like filtered_df = df[result]
Aucun commentaire:
Enregistrer un commentaire