Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

pandas read_csv drop column

# Read column names from file
cols = list(pd.read_csv("sample_data.csv", nrows =1))
print(cols)
# Define unused cols
unused = ['col1', 'col2']
# Use list comprehension to remove the unwanted column in **usecol**
df= pd.read_csv("sample_data.csv", usecols =[i for i in cols if i not in unused])
 
PREVIOUS NEXT
Tagged: #pandas #drop #column
ADD COMMENT
Topic
Name
4+5 =