前言
2022/03/01,三月的第一天,学习了Python读取Excel数据的两种方法;Python将Excel的数据存入列表中;求列表的最大值
一、Python读取数据
1.pandas的read_excel读取
import pandas as pd
custom_data = pd.read_excel(r'D:\python_resource\001analy_base\foundations-for-analytics-with-python-master\applications\historical_files\suppliers.xlsx',
sheet_name='suppliers_2013')
print(custom_data)
输出结果
2.xlrd.open_workbook()函数读取
注:excel文件要和程序保存在一个目录下
import xlrd
import xlwt
def read_excel():
#打开文件
workExcel = xlrd.open_workbook('suppliers.xlsx')
#获取所有sheet的名字
allSheet = workExcel.sheet_names()
print(allSheet)
#按索引号获取sheet的名字(string)类型
sheetName = workExcel.sheet_names()[0]
print(sheetName)
#获取sheet内容
sheet1 = workExcel.sheet_by_index(0)
sheet2 =