Search
 
SCRIPT & CODE EXAMPLE
 

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

PREVIOUS NEXT
Code Example
Python :: python merge strings 
Python :: discord.py get user id 
Python :: dict map() 
Python :: tensorflow.keras.utils.to_categorical 
Python :: create a database in python 
Python :: dataframe print column 
Python :: python set attribute by string name 
Python :: python how to extract a string from another string 
Python :: python dataframe calculate difference between columns 
Python :: seaborn 
Python :: python is instance 
Python :: has no attribute python 
Python :: from django.urls import re_path 
Python :: close a file python 
Python :: queue in python 
Python :: python compare each item of one list 
Python :: best algorithm for classification 
Python :: python get class from string 
Python :: convert python list to pyspark column 
Python :: python jinja2 from string 
Python :: python in stack 
Python :: python IndexError: list assignment index out of range 
Python :: reply to a message discord.py 
Python :: python glob subdirectories 
Python :: read xml file in python 
Python :: spacy get number of tokens 
Python :: Python format() Method for Formatting Strings 
Python :: get height of image in pygame 
Python :: change column values based on another column pandas 
Python :: check if key exists in sesson python flask 
ADD CONTENT
Topic
Content
Source link
Name
4+3 =