尝试使用适用于 python 的 panda 使用简单的代码行从数据帧中删除列。
我尝试删除的列的名称是"评论">
import pandas as pd
location2 = 'datasets_travel_times.csv'
travelTime_df= pd.read_csv(location2)
traveltime_df = travelTime_df.drop('Comments',1)
traveltime_df
它没有给出任何错误;但是我打印数据帧并看到"注释"列仍然存在
这里有 2 种可能的方法:-
第一种方式:-
travelTime_df.drop(['Comments'], axis=1)
第二种方式:-
travelTime_df.drop(columns=['Comments'])
添加深入探讨的链接:- https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.drop.html