且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用Python从数据框中删除多列

更新时间:2023-11-18 22:52:16

要同时删除pandas中的多列,可以指定列名称,如下所示.如果希望在同一数据帧中受更改影响的列,则需要选项inplace=True.否则将其删除.

To delete multiple columns at the same time in pandas, you could specify the column names as shown below. The option inplace=True is needed if one wants the change affected column in the same dataframe. Otherwise remove it.

flight_data_copy.drop(['TailNum', 'OriginStateFips', 
                'DestStateFips', 'Diverted'], axis=1, inplace=True)

来源: Python熊猫-在一个命令中从数据框中删除多个序列