Чтение файла Sharepoint Excel в Python - Pandas

avatar
Dana7371
1 июля 2021 в 17:40
849
1
1

У меня возникли проблемы с чтением файла SharePoint Excel с использованием Python Pandas и Office 365. Он выводит «Аутентификация прошла успешно», но имеет несколько ошибок:

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)```
Источник

Ответы (1)

avatar
Hummer
5 июля 2021 в 02:55
0

На этот вопрос был дан ответ здесь TypeError with pandas.read_excel. В общем, просто замените sheetname на sheet_name в вашем коде. Должно работать хорошо.