获取Pandas读取Excel后所有列名的⼏种⽅法
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 = lumns.values            # 2.通过columns字段获取,返回⼀个numpy型的array
columns_name3 = list()          # lumns 返回Index,可以通过 tolist(), 或者 list(array)转换为list
print('*' * 10)
print(columns_name1)
print('*' * 20)
python怎么读取excel某一列
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' **********
['id', 'customer_code', 'customer_name', 'delivery_address', 'purchasing_agency', 'contact_phone', 'c
ontact_tel', 'contact_fax', 'qq', 'wechat', 'email', 'director', 'director_iphone', 'director_telephone' ********************
['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' *****
***********************************
['id', 'customer_code', 'customer_name', 'delivery_address', 'purchasing_agency', 'contact_phone', 'contact_tel', 'contact_fax', 'qq', 'wechat', 'email', 'director', 'director_iphone', 'director_telephone'

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。