seven18
import pandas as pd

data = pd.read_excel(\'客户信息.xlsx\')
# 获取Pandas读取Excel后所有列名的几种方法
print(list(data)) # 0. 直接使用 list 关键字,返回一个list
columns_name1 = [column for column in data] # 1.链表推倒式_获取Pandas列名的几种方法
columns_name2 = data.columns.values # 2.通过columns字段获取,返回一个numpy型的array
columns_name3 = data.columns.tolist() # 4.df.columns 返回Index,可以通过 tolist(), 或者 listarray) 转换为list

print(\'*\' * 10)
print(columns_name1)
print(\'*\' * 20)
print(columns_name2, type(columns_name2))
print(\'*\' * 30)
print(columns_name3, type(columns_name2))
print(\'*\' * 40)
print(list(columns_name3))

PyDev console: starting.
Python 3.9.0 (tags/v3.9.0:9cf6752, Oct 5 2020, 15:34:40) [MSC v.1927 64 bit (AMD64)] on win32
runfile(\'D:/pyexcel/temppandas.py\', wdir=\'D:/pyexcel\')
[\'id\', \'customer_code\', \'customer_name\', \'delivery_address\', \'purchasing_agency\', \'contact_phone\', \'contact_tel\', \'contact_fax\', \'qq\', \'wechat\', \'email\', \'director\', \'director_iphone\', \'director_telephone\', \'director_fax\', \'registered_address\', \'bank\', \'account_number\', \'creation_date\', \'unified_social_credit_code\', \'Unnamed: 20\', \'office_address\', \'remarks\', \'creation_date.1\', \'note_appended\', \'client\', \'credit_line\', \'use_line\']
**********
[\'id\', \'customer_code\', \'customer_name\', \'delivery_address\', \'purchasing_agency\', \'contact_phone\', \'contact_tel\', \'contact_fax\', \'qq\', \'wechat\', \'email\', \'director\', \'director_iphone\', \'director_telephone\', \'director_fax\', \'registered_address\', \'bank\', \'account_number\', \'creation_date\', \'unified_social_credit_code\', \'Unnamed: 20\', \'office_address\', \'remarks\', \'creation_date.1\', \'note_appended\', \'client\', \'credit_line\', \'use_line\']
********************
[\'id\' \'customer_code\' \'customer_name\' \'delivery_address\'
\'purchasing_agency\' \'contact_phone\' \'contact_tel\' \'contact_fax\' \'qq\'
\'wechat\' \'email\' \'director\' \'director_iphone\' \'director_telephone\'
\'director_fax\' \'registered_address\' \'bank\' \'account_number\'
\'creation_date\' \'unified_social_credit_code\' \'Unnamed: 20\'
\'office_address\' \'remarks\' \'creation_date.1\' \'note_appended\' \'client\'
\'credit_line\' \'use_line\'] <class \'numpy.ndarray\'>
******************************
[\'id\', \'customer_code\', \'customer_name\', \'delivery_address\', \'purchasing_agency\', \'contact_phone\', \'contact_tel\', \'contact_fax\', \'qq\', \'wechat\', \'email\', \'director\', \'director_iphone\', \'director_telephone\', \'director_fax\', \'registered_address\', \'bank\', \'account_number\', \'creation_date\', \'unified_social_credit_code\', \'Unnamed: 20\', \'office_address\',

分类:

技术点:

相关文章:

  • 2022-12-23
  • 2022-02-16
  • 2022-01-25
  • 2021-11-07
  • 2022-02-10
  • 2021-06-03
  • 2021-11-28
猜你喜欢
  • 2022-02-12
  • 2022-12-23
  • 2022-12-23
  • 2021-10-25
  • 2021-10-17
  • 2021-06-05
相关资源
相似解决方案