我有一些代码,可以从数据URI中获取结构化信息,并将其显示为表格(使用Pandas DataFrame)。
包装和重要变量(仅用于了解情况)
import { Grass, GrassEater } from "./classification.js";
重要部分:
import rdfpandas.graph # tika importeets Anaconda sisteemaa
import rdflib # tika importeets Anaconda sisteemaa
import pandas as pd # tika importeets Anaconda sisteemaa
from ipywidgets import widgets # pievienots GUI (button, textbox u.tml.) + event handler
from IPython.display import clear_output # dod iespēju izdzēst sūnas "Out" saturu, izmantojot komandu
# Palielina ekrāna izmēru kodam un izvadam līdz ekrāna izmēŗam - 100%
from IPython.core.display import display, HTML
display(HTML("<style>.container { width:100% !important; }</style>"))
g_DBp = rdflib.Graph()
g_DBp.load('http://dbpedia.org/resource/KonoSuba')
# defining arrays (subject_array, predicate_array, object_array) and import info from data graph
# ...
d1 = {'Subject': subject_array, 'Predicate': predicate_array, 'Object': object_array}
df1 = pd.DataFrame(data=d1)
dbp_button = widgets.Button(description="DBPedia")
display(dbp_button)
kitsu_button = widgets.Button(description="Kitsu API")
display(kitsu_button)
out = widgets.Output()
程序显示两个按钮-如果单击“ dbp_button”,则信息表显示为“输出”,如果单击“ dbp_button”,则清除输出。
问题: 为什么通过注释最后几行来更改函数“ on_button_clicked”:
def on_button_clicked(b):
with out:
clear_output(True)
if(b.description == "DBPedia"):
display(df1)
else:
clear_output(True)
dbp_button.on_click(on_button_clicked)
kitsu_button.on_click(on_button_clicked)
out
我需要点击“ kitsu_button” 两次以清除输出?