情况说明
py文件和数据已经在同一文件路径中,excel表名为“BloombergESG_ClosePrice.xlsx”,内含两张工作表。第一张工作表名为“ESG_score”,数据较少;第二张工作表名为“all_stock_close(1209)”,数据较多。
import pandas as pd
方法一
先读取文档中有哪些表格,不做具体数据读取,第一步很快;第二部根据具体需要读取工作表,不读取无关数据,速度也快。
xl = pd.ExcelFile('BloombergESG_ClosePrice.xlsx')
ESG_table2 = xl.parse(xl.sheet_names[0])
cp_table = xl.parse(xl.sheet_names[1],index_col=('time'))
方法二
不读取无关数据,速度较快,但需要提前精确知道文档中具体表名
ESG_table1 = pd.read_excel('BloombergESG_ClosePrice.xlsx',sheet_name='ESG_score',header=0)
方法三
设置参数None,excel 将读取为字典格式(读取全部数据,耗时较长),从字典中取表(前面已经读好了,这步调取很快)
df = pd.read_excel('BloombergESG_ClosePrice.xlsx',None)
ESG_table3 = df[list(df.keys())[0]]