Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

Drop a single column by index

import pandas as pd

# create a sample dataframe
data = {
    'A': ['a1', 'a2', 'a3'],
    'B': ['b1', 'b2', 'b3'],
    'C': ['c1', 'c2', 'c3'],
    'D': ['d1', 'd2', 'd3']
}

df = pd.DataFrame(data)

# print the dataframe
print("Original Dataframe:
")
print(df)

# remove column 
df = df.drop(df.columns[2], axis=1)

print("
After dropping C:
")
print(df)
Comment

PREVIOUS NEXT
Code Example
Python :: how to check columns with the numerical values 
Python :: formula for nth fibonnaci number 
Python :: Python Tkinter Entry Widget Syntax 
Python :: Python Tkinter SpinBox Widget Syntax 
Python :: nim game in python 
Python :: generate a random string with lowercase uppercase and numbers 
Python :: Difference between the remove() method and discard() method of sets in python 
Python :: Move Mouse Every Minute Using Python 3 & PyAutoGUI 
Python :: Change the transparency of histogram 
Python :: tables in django 
Python :: How to join or combine multiple csv files with concatenate and export dataframe to csv format 
Python :: python async get result 
Python :: handling files in django 
Python :: python convert string object to int object 
Python :: Set Date In Python 
Python :: generate a hash/secret python 
Python :: pyPS4Controller usage 
Python :: way to close file python with staement 
Python :: msg to pdf converter using python 
Python :: Source code: Matrix Addition using Nested Loop 
Python :: hash tables in python 
Python :: run python script in synology sample 
Python :: python array_combine 
Python :: torch.cuda.randn 
Python :: pandas map 
Python :: validate delete inline formset django 
Python :: come mettere una scelta su python 
Python :: Reading from a file way01 
Python :: Python String Membership 
Python :: python read and write lines in file 
ADD CONTENT
Topic
Content
Source link
Name
7+3 =