pandas:删除多个列,这些列在列表中命名并分配给新的数据帧

问题描述 投票:-2回答:2
list = ['pymnt_plan',
 'recoveries',
 'collection_recovery_fee',
 'policy_code',
 'num_tl_120dpd_2m',
 'hardship_flag',
 'debt_settlement_flag_date',
 'settlement_status',
 'settlement_date',
 'settlement_amount',
 'settlement_percentage',
 'settlement_term']

如何删除列表中的名称并分配给新数据框的多个列?

python pandas
2个回答
1
投票

你可以做

new_df = df[list]
df = df.drop(columns=list)

0
投票

在Pandas 0.20.3中使用'df = df.drop(columns = list)'我得到:

    TypeError: drop() got an unexpected keyword argument 'columns'

所以你可以用它代替:

    df = df.drop(axis=1, labels=list)
© www.soinside.com 2019 - 2024. All rights reserved.