6.7. Sharing and Downloading

This section covers some tools to share and download your data.

6.7.1. Datapane: Publish your Python Objects on the Web in 2 Lines of Code

!pip install datapane plotly

If you want to put together your pandas.DataFrame, interactive charts such as Plotly, Bokeh, Altair, or markdown into a nice report and publish it on the web, try Datapane. The code below shows how you can publish your Python objects using Datapane in a few lines of code.

import datapane as dp
import pandas as pd
import numpy as np
import plotly.express as px

# Scripts to create df and chart
df = px.data.gapminder()

chart = px.scatter(
    df.query("year==2007"),
    x="gdpPercap",
    y="lifeExp",
    size="pop",
    color="continent",
    hover_name="country",
    log_x=True,
    size_max=60,
)

# Once you have the df and the chart, simply use
r = dp.Report(
    dp.Text("my simple report"),  # add description
    dp.DataTable(df),  # create a table
    dp.Plot(chart),  # create a chart
)

# Publish your report
r.upload(name="example")

Uploading report and associated data - please wait...

Report successfully uploaded, click here to view and share your report

Link to Datapane

Link to my article about Datapane

6.7.2. gdown: Download a File from Google Drive in Python

!pip install gdown 

If you want to download a file from Google Drive in Python, use gdown. All you need to specify is the URL link.

import gdown

# Format of url: https://drive.google.com/uc?id=YOURFILEID
url = "https://drive.google.com/uc?id=1jI1cmxqnwsmC-vbl8dNY6b4aNBtBbKy3"
output = "Twitter.zip"

gdown.download(url, output, quiet=False)
Downloading...
From: https://drive.google.com/uc?id=1jI1cmxqnwsmC-vbl8dNY6b4aNBtBbKy3
To: /home/khuyen/book/book/Chapter4/Twitter.zip
120MB [00:09, 12.1MB/s] 
'Twitter.zip'

Link to gdown.