How to delete a column in Jupyter?
To remove a data column in Jupyter Notebook, you can utilize the drop() function in the pandas library.
First, make sure you have imported the pandas library, then use the following code to delete a column from the data.
import pandas as pd
# 读取数据集
df = pd.read_csv("dataset.csv")
# 删除数据列
df.drop("column_name", axis=1, inplace=True)
In the code above, “dataset.csv” represents the path to the dataset file, while “column_name” is the name of the data column to be deleted.
Setting the axis parameter to 1 removes columns, while setting the inplace parameter to True modifies the original dataset. To avoid modifying the original dataset, set the inplace parameter to False and assign the result to another variable.
Please replace “dataset.csv” and “column_name” with the actual file path of your dataset and the name of the column to be deleted.