Skip to main content
 首页 » 编程设计

python之运行 df.columns 后显示所有列

2025年01月19日11del

目前我的 DataFrame 中有 120 列。当我执行

df.columns  

我得到一个截断的列表,其中我只看到 20 列而不是 120 列:

Index(['Reporting_FI', 'Reporting_FI_identification', 
   'Reporting_FI_identification_type', 'Reporting_FI_street_address_1', 
   'Reporting_FI_street_address_2', 'Reporting_FI_city', 
   'Reporting_FI_state', 'Reporting_FI_postal_code', 
   'Reporting_FI_country_code', 'Transaction_date', 
   ... 
   'FI_country_code_3', 'FI_name_4', 'FI_branch_4', 'FI_identification_4', 
   'FI_identification_type_4', 'FI_account_number_4', 'FI_city_4', 
   'FI_state_4', 'FI_country_code_4', 'Additional_infomation_2'], 
  dtype='object', length=120) 

如何调整它以显示所有 120 个?

我不是在寻找:

pd.set_option('display.max_columns', 120) 

谢谢

请您参考如下方法:

一种简单的方法是在打印前转换为list:

res = df.columns.tolist() 
 
print(res)