由于我们无法复制数据,因此可能会有不同的情况和不同的解决方案。
我列出了一些可能会引导你走向正确方向的情况...
情况一:
如果您使用的是旧的 python 版本,那么您应该简单地尝试下面的sheetname 与旧版本和sheet_name 与新版本。
import pandas as pd
df = pd.read_excel(file_with_data, sheetname=sheet_with_data)
或
您可以改用pd.ExcelFile ..
xls = pd.ExcelFile('path_to_file.xls')
df1 = pd.read_excel(xls, 'in')
或
xl = pd.ExcelFile(path)
# xl = pd.ExcelFile("Full_Path_of _file")
xl.sheet_names
[u'in', u'in1', u'in2']
df = xl.parse("in")
df.head()
或
df = pd.read_excel(open('your_xls_xlsx_filename','rb'), sheet_name='Sheet 1')
# or using sheet index starting 0
df = pd.read_excel(open('your_xls_xlsx_filename','rb'), sheet_name=1)
注意:选择 sheetname 参数需要仔细选择 python pandas 版本>
对于较旧的python版本:使用sheetname
对于新的python版本:使用sheet_name
情况2:
直接从右键文件属性复制地址-安全会导致这个问题所以复制粘贴文件路径也会产生这些问题而没有其他明显问题
解决
It has nothing to do with the backslash /forward slash in the path, and it has nothing to do with whether the path contains. There are two solutions
1 Enter the path manually
2 Open this path in Explorer, then copy
一般阅读约定:
# When the parameter is None, all tables are returned, which is a dictionary of tables;
sheet = pd.read_excel('example.xls',sheet_name= None)
# When the parameter is list = [0, 1, 2, 3], the returned multi-table is also a dictionary
sheet = pd.read_excel('example.xls',sheet_name= 0)
sheet = pd.read_excel('example.xls',sheet_name= [0,1])
#The data of the table can also be read according to the name of the table header or the position of the table
sheet = pd.read_excel('example.xls',sheet_name= 'Sheet0')
sheet = pd.read_excel('example.xls',sheet_name= ['Sheet0','Sheet1'])
sheet = pd.read_excel('example.xls',sheet_name=[0,1,'Sheet3'])