I have a csv in the documents section of a SharePoint site. I would like to import it in Pandas. Of course is I use just the normal code below I get HTTP error 403 Forbidden.
import pandas
df = pandas.read_csv('link from sharepoint')
How do I get SharePoint authentication to work using Python so Pandas can read the csv file.
I have already searched and tried code in several internet posts, but either the code is too generic that I do not know what it means e.g.
username = 'YourDomain\\account'
or
user = r'SERVER\user'
or it just didn't.
Is there a simple way to get authentication to work and import the file in Pandas?
Relatively easy solution with sharepy:
import io
import sharepy
import pandas as pd
URL = 'https://yoursharepointsite.sharepoint.com'
FILE_URL = '/sites/...path to your file.../yourfilename.csv'
SHAREPOINT_USER = 'yourusername'
SHAREPOINT_PASSWORD = 'yourpassword'
s = sharepy.connect(URL, username=SHAREPOINT_USER, password=SHAREPOINT_PASSWORD).
r = s.get(URL+FILE_URL)
f = io.BytesIO(r.content)
df = pd.read_csv(f)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With