Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

Drop multiple columns with their 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 columns C and D
df = df.drop(df.columns[[2, 3]], axis=1)

print("
After dropping columns C and D:
")
print(df)
Source by datascienceparichay.com #
 
PREVIOUS NEXT
Tagged: #Drop #multiple #columns #index
ADD COMMENT
Topic
Name
6+2 =