Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR 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)
Source by datascienceparichay.com #
 
PREVIOUS NEXT
Tagged: #Drop #single #column #index
ADD COMMENT
Topic
Name
9+4 =