I want to use python “loop” for drop list

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP


I want to use python “loop” for drop list


import pandas as pd
import os
import xlrd

os.chdir('D:python')
file_name='D:python\test.xlsx'
sheet='test01'
df=pd.DataFrame(pd.read_excel(file_name,sheet))
df.drop(list(df.filter(regex = 'Abc')), axis = 1, inplace = True)
df.drop(list(df.filter(regex = 'def')), axis = 1, inplace = True)
df.drop(list(df.filter(regex = 'ghi')), axis = 1, inplace = True)
df.drop(list(df.filter(regex = 'jkl')), axis = 1, inplace = True)
df.drop(list(df.filter(regex = 'mno')), axis = 1, inplace = True)
df.drop(list(df.filter(regex = 'pqr')), axis = 1, inplace = True)



I want all variables(a to r) in one list so that all above condition passed in one sentence. for this I want to use loop. Any suggestion on this.




1 Answer
1



Try like this :


df=pd.DataFrame(pd.read_excel(file_name,sheet))
li = ['Abc', 'def', 'ghi', 'lmn']
for i in li:
df.drop(list(df.filter(regex = i)), axis = 1, inplace = True)






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Arduino Mega cannot recieve any sketches, stk500_recv() programmer is not responding

Visual Studio Code: How to configure includePath for better IntelliSense results

C++ virtual function: Base class function is called instead of derived