Search
 
SCRIPT & CODE EXAMPLE
 

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])
Comment

PREVIOUS NEXT
Code Example
Python :: Python - How To Convert Bytearray to String 
Python :: python run system commands 
Python :: get end of string python 
Python :: flatten lists python 
Python :: scaling 
Python :: cannot unpack non-iterable int object when using python dicitonary 
Python :: python chatbot api 
Python :: how to debug python code in visual studio code 
Python :: tuple unpacking 
Python :: how to do the sum of list in python 
Python :: python glob how to read all txt files in folder 
Python :: python class variables 
Python :: python script to read qr code 
Python :: how to remove trailing zeros in python 
Python :: how to sleep() in python 
Python :: tkinter filedialog 
Python :: python how to add 2 numbers 
Python :: no module named 
Python :: how to create an auto clicker in python 
Python :: python write error to file 
Python :: fastest sorting algorithm java 
Python :: non blocking socket python 
Python :: how to represent equation in pytho 
Python :: if something in something python example 
Python :: string to list of characters python 
Python :: somalia embassy in bangladesh 
Python :: pyglet on button press 
Python :: forward checking algorithm python 
Python :: john cabot 
Python :: keylogger to exe 
ADD CONTENT
Topic
Content
Source link
Name
5+6 =