Importing files from github

A quick post today. I’ve had to pull some files from my work github repository to run analysis. In case you run into that challenge, the requests module in python offers a simple solution to the problem. I may update this post in the future with an SSH connection to github but for now, here’s what I did.


# Import necessary modules
import requests
import io
import pandas as pd


# Connect to git file
req = requests.get('https://raw.githubusercontent.com/GitRepoName/FolderName/FileName.csv', auth=('yourgitusername', 'yourgitpassword')).content
# Convert file into a dataframe
data = pd.read_csv(io.StringIO(req.decode('utf-8')))

Voila!

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s