I am having trouble reading a SharePoint excel file using Python Pandas and Office 365. It is outputting "Authentication Successful" but has a few errors stating:
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'
My full Code is:
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)```
This question was answered here TypeError with pandas.read_excel . All in all, just replace sheetname
with sheet_name
in your code. Should work well.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.