Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

Drop multiple columns by name

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(['C', 'D'], axis=1)

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