pandas read csv drop column

Solutions on MaxInterview for pandas read csv drop column by the best coders in the world

showing results for - "pandas read csv drop column"
Jona
27 Nov 2017
1# Read column names from file
2cols = list(pd.read_csv("sample_data.csv", nrows =1))
3print(cols)
4# Define unused cols
5unused = ['col1', 'col2']
6# Use list comprehension to remove the unwanted column in **usecol**
7df= pd.read_csv("sample_data.csv", usecols =[i for i in cols if i not in unused])