The code drops the columns that are not required from the table:

inputData <- inputData[,!(colnames(inputData) %in% c('col1','col2',''))]

Need help converting this line to python, I'm struggling with it as I'm fairly new to python ;-;

1

Best Answer


Assuming you need translation to third-party Pandas which unlike R, data frames are not standard library objects in Python, consider Index.isin to replace %in% and tilde negation operator, ~, to replace !:

inputData = inputData[inputData.columns[~inputData.columns.isin(['col1','col2',''])]]

Alternatively, try Index.difference:

inputData = inputData[inputData.columns.difference(['col1','col2',''])]