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']
如何删除列表中的名称并分配给新数据框的多个列?
你可以做
new_df = df[list]
df = df.drop(columns=list)
在Pandas 0.20.3中使用'df = df.drop(columns = list)'我得到:
TypeError: drop() got an unexpected keyword argument 'columns'
所以你可以用它代替:
df = df.drop(axis=1, labels=list)