read csv from SharePoint with Pandas (Python authentication code)
Relatively easy solution with sharepy:
import ioimport sharepyimport pandas as pdURL = '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)
To my knowledge you can't, but what you can do is use an API to connect python to SharePoint.
What I do is use SharePlum -> download via pip (pip install shareplum)
import sys, pandas, datetimefrom requests_ntlm import HttpNtlmAuthfrom shareplum import Siteauth = HttpNtlmAuth('DOMAIN' + '\\' + str(username), str(password)) site = Site('sharepointsiteurl', auth=auth, verify_ssl=True) # set to False if behind firewallsite_list = site.List('Name of List')df = pandas.DataFrame.from_dict(site_list)# then do what you need to in Pandas
Edit:Since you are trying to download a CSV file. use the python-sharepoint api
same thing as above but instead of the
site_list = site.List('Name of List')# do insteadsite.download('nameoffile.csv', 'D:/location/to/save.csv')
As long as your SP username and password are identical to your Windows login credentials, which is very common, the following should work (mostly taken from here):
import requestsfrom requests_negotiate_sspi import HttpNegotiateAuthimport pandas as pdurl = 'https://yoursharepointsite.sharepoint.com'fileUrl = '/sites/...path to your file.../yourfilename.csv'r = requests.get(url + fileUrl, auth=HttpNegotiateAuth())df = pd.read_csv(r.text)
I tested it with read_excel(r.content)
, since I had an XLSX file instead of a CSV. It seems that XLSX files are treated as binaries. But with CSV being parsed as text, it should work as posted. Feel free to report back.