如何使用Pandas phyton库从数据框中删除列?

问题描述 投票:0回答:1

[尝试使用简单的代码行使用熊猫作为phyton从数据框中删除列。

我要删除的列的名称是“注释”

traveltime_df = travelTime_df.drop('Comments',1)

它没有给出任何错误;但随后我打印了数据框,并看到“注释”列仍然存在

pandas
1个回答
0
投票

这里有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

© www.soinside.com 2019 - 2024. All rights reserved.