ipysheet
#
ipysheet verbindet ipywidgets mit tabellarischen Daten. Es fügt im Wesentlichen zwei Widgets hinzu: ein Cell widget und ein Sheet widget. Darüberhinaus gibt es noch Hilfsfunktionen zum Erstellen von Tabellenzeilen und -spalten sowie zur Formatierung und Gestaltung von Zellen.
Siehe auch:
Installation#
ipysheet
lässt sich einfach mit Pipenv installieren:
$ pipenv install ipysheet
Import#
[1]:
import ipysheet
Zellformatierung#
[2]:
sheet1 = ipysheet.sheet()
cell0 = ipysheet.cell(0, 0, 0, numeric_format="0.0", type="numeric")
cell1 = ipysheet.cell(1, 0, "Hello", type="text")
cell2 = ipysheet.cell(0, 1, 0.1, numeric_format="0.000", type="numeric")
cell3 = ipysheet.cell(1, 1, 15.9, numeric_format="0.00", type="numeric")
cell4 = ipysheet.cell(2, 2, "14-02-2019", date_format="DD-MM-YYYY", type="date")
sheet1
Beispiele#
Interaktive Tabelle#
[3]:
from ipywidgets import FloatSlider, Image, IntSlider
slider = FloatSlider()
sheet2 = ipysheet.sheet()
cell1 = ipysheet.cell(0, 0, slider, style={"min-width": "122px"})
cell3 = ipysheet.cell(1, 0, 42.0, numeric_format="0.00")
cell_sum = ipysheet.cell(2, 0, 42.0, numeric_format="0.00")
@ipysheet.calculation(inputs=[(cell1, "value"), cell3], output=cell_sum)
def calculate(a, b):
return a + b
sheet2
Numpy#
[4]:
import numpy as np
from ipysheet import from_array, to_array
arr = np.random.randn(6, 10)
sheet = from_array(arr)
sheet
[5]:
arr = np.array([True, False, True])
sheet = from_array(arr)
sheet
[6]:
to_array(sheet)
[6]:
array([[ True],
[False],
[ True]])
Tabellensuche#
[7]:
import numpy as np
import pandas as pd
from ipysheet import from_dataframe
from ipywidgets import Text, VBox, link
df = pd.DataFrame(
{
"A": 1.0,
"B": pd.Timestamp("20130102"),
"C": pd.Series(1, index=list(range(4)), dtype="float32"),
"D": np.array([False, True, False, False], dtype="bool"),
"E": pd.Categorical(["test", "train", "test", "train"]),
"F": "foo",
}
)
df.loc[[0, 2], ["B"]] = np.nan
s = from_dataframe(df)
search_box = Text(description="Search:")
link((search_box, "value"), (s, "search_token"))
VBox((search_box, s))
Plotten editierbarer Tabellen#
[8]:
import bqplot.pyplot as plt
import numpy as np
from ipysheet import cell, column, sheet
from ipywidgets import HBox
from traitlets import link
size = 18
scale = 100.0
np.random.seed(0)
x_data = np.arange(size)
y_data = np.cumsum(np.random.randn(size) * scale)
fig = plt.figure()
axes_options = {
"x": {"label": "Date", "tick_format": "%m/%d"},
"y": {"label": "Price", "tick_format": "0.0f"},
}
scatt = plt.scatter(x_data, y_data, colors=["red"], stroke="black")
fig.layout.width = "70%"
sheet1 = sheet(rows=size, columns=2)
x_column = column(0, x_data)
y_column = column(1, y_data)
link((scatt, "x"), (x_column, "value"))
link((scatt, "y"), (y_column, "value"))
HBox((sheet1, fig))