ValueError: Usecols do not match columns, columns expected but not found: ['C', 'A']…
Jump to turn (6)
- 1ValueError: Usecols do not match columns, columns expected but not found: ['C',
- 2sheetscolumns = { 'ICP备案': "['A', 'C']", 'APP': ['A', 'B', 'E'], '微信小程序':['A','B
- 3sheetscolumns = { 'ICP备案': ['A', 'C'], 'APP': ['A', 'B', 'E'], '微信小程序':['A','B '
- 4sheetscolumns = { 'ICP备案': ['A', 'C'], 'APP': ['A', 'B', 'E'], '微信小程序':['A','B '
- 5ValueError: Usecols do not match columns, columns expected but not found: ['A',
- 6sheetscolumns = { 'ICP备案': ['A', 'C'], 'APP': ['A', 'B', 'E'], '微信小程序':['A','B '
- User
ValueError: Usecols do not match columns, columns expected but not found: ['C', 'A'] (sheet: ICP备案) 这个报错是什么原因
- Assistant
这个报错是因为你在使用
pandas库的read_excel()函数读取Excel文件时,指定了参数usecols来选择读取的列,但是你指定的列在Excel文件的工作表中不存在。根据报错信息可知,你指定了
['C', 'A']作为usecols的值,但是这两列在ICP备案工作表中并不存在。你需要确认一下要读取的列是否正确,并且检查一下Excel文件中的工作表和列名是否和你的代码中一致。 - User
sheets_columns = { 'ICP备案': "['A', 'C']", 'APP': ['A', 'B', 'E'], '微信小程序':['A','B '], '微信公众号':['A','B ', 'C'] }
创建一个字典来存储读取到的数据
data_frames = {}
打开Excel文件
with pd.ExcelFile(excel_file_path) as xls: # 遍历需要的工作表和列 for sheet_name, columns in sheets_columns.items(): # 检查工作表是否存在 print(sheet_name) print(columns) if sheet_name in xls.sheet_names: # 读取指定列 data_frame = pd.read_excel(xls, sheet_name=sheet_name, usecols=columns) 这段代码有什么问题