Skip to content

Instantly share code, notes, and snippets.

@marksparrish
Created January 5, 2022 15:20
Show Gist options
  • Save marksparrish/2d1af59da33d5b8c455e1f4fe45efe50 to your computer and use it in GitHub Desktop.
Save marksparrish/2d1af59da33d5b8c455e1f4fe45efe50 to your computer and use it in GitHub Desktop.
Dropbox Zipfile CSVs to pandas
import io
import zipfile
import dropbox
import pandas as pd
def get_dropbox():
dropbox_path = "path/to/dropbox/files"
dbx = dropbox.Dropbox('DROPBOX_KEY')
# get listing of files
dbx_files = dbx.files_list_folder(dropbox_path)
# sort to get the latest file
dbx_files.entries.sort(key = lambda d: d.client_modified, reverse=True)
df = pd.DataFrame()
_, res = dbx.files_download(dbx_files.entries[0].path_lower)
with io.BytesIO(res.content) as stream:
zf = zipfile.ZipFile(stream)
for f in zf.namelist():
try:
dfs = pd.read_csv(zf.open(f), sep="\t", dtype=str, low_memory=False, encoding_errors='ignore')
df = df.append(dfs, ignore_index=True)
except ValueError:
pass
return df
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment