Developed in sessions launched from here and served via the MyBinder service. Go there and click on a 'launch binder' badge.
%pip install openpyxl
Collecting openpyxl Obtaining dependency information for openpyxl from https://files.pythonhosted.org/packages/30/d0/abcdb0669931be3a98881e6d7851605981693e93a7924061c67d0cd9f292/openpyxl-3.1.4-py2.py3-none-any.whl.metadata Downloading openpyxl-3.1.4-py2.py3-none-any.whl.metadata (2.5 kB) Collecting et-xmlfile (from openpyxl) Obtaining dependency information for et-xmlfile from https://files.pythonhosted.org/packages/96/c2/3dd434b0108730014f1b96fd286040dc3bcb70066346f7e01ec2ac95865f/et_xmlfile-1.1.0-py3-none-any.whl.metadata Downloading et_xmlfile-1.1.0-py3-none-any.whl.metadata (1.8 kB) Downloading openpyxl-3.1.4-py2.py3-none-any.whl (251 kB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 251.4/251.4 kB 7.6 MB/s eta 0:00:00 Downloading et_xmlfile-1.1.0-py3-none-any.whl (4.7 kB) Installing collected packages: et-xmlfile, openpyxl Successfully installed et-xmlfile-1.1.0 openpyxl-3.1.4 Note: you may need to restart the kernel to use updated packages.
# use any example xlsx as staring point; this was near top when I googled 'sample .xlsx file'
!curl -OL https://github.com/frictionlessdata/datasets/raw/main/files/excel/sample-1-sheet.xlsx
% Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0 100 3698 100 3698 0 0 13251 0 --:--:-- --:--:-- --:--:-- 13251
import ipywidgets as widgets
from IPython.display import display
output = widgets.Output()
import pandas as pd
def load_data():
df = pd.read_excel('sample-1-sheet.xlsx',engine='openpyxl',dtype=str)
with output:
output.clear_output() # from 'Output widgets: leveraging Jupyter’s display system' https://ipywidgets.readthedocs.io/en/latest/examples/Output%20Widget.html
display(df)
def on_sample_data_click(event):
load_data()
text_caption = widgets.HTML(value="<h2>Showing data</h1><h2>")
vbox_text = widgets.VBox([text_caption])
display(vbox_text)
load_sample_data = widgets.Button(description='Click to show', layout=dict(width='auto', height='auto'))
load_sample_data.on_click(on_sample_data_click)
display(load_sample_data)
display(output)
VBox(children=(HTML(value='<h2>Showing data</h1><h2>'),))
Button(description='Click to show', layout=Layout(height='auto', width='auto'), style=ButtonStyle())
Output()