我在使用Python Pandas和Office 365读取SharePoint excel文件时遇到问题。它正在输出";认证成功";但有一些错误说明:
Traceback (most recent call last): File "/Users/gfgdfg/Try.py", line 28, in <module> df = pd.read_excel(bytes_file_obj, sheetname = None) File "/Users/venv/lib/python3.9/site-packages/pandas/util/_decorators.py", line 299, in wrapper return func(*args, **kwargs) TypeError: read_excel() got an unexpected keyword argument 'sheetname'
我的完整代码是:
from office365.runtime.auth.authentication_context import AuthenticationContext
from office365.sharepoint.client_context import ClientContext
from office365.sharepoint.files.file import File
import pandas as pd
url = 'https://dfsdfksdfhk.sharepoint.com/:x:/s/dkfjsldkfjldjfC4IT3'
username = 'email@outlook.com'
password = 'mypassword'
ctx_auth = AuthenticationContext(url)
if ctx_auth.acquire_token_for_user(username, password):
ctx = ClientContext(url, ctx_auth)
web = ctx.web
ctx.load(web)
ctx.execute_query()
print("Authentication successful")
response = File.open_binary(ctx, url)
#save data to BytesIO stream
bytes_file_obj = io.BytesIO()
bytes_file_obj.write(response.content)
bytes_file_obj.seek(0) #set file object to start
#read excel file and each sheet into pandas dataframe
df = pd.read_excel(bytes_file_obj, sheetname = None)
print(df)```
这个问题在这里用pandas.read_excel回答了TypeError。总之,只需在代码中用sheet_name
替换sheetname
。应该工作得很好。