python - 在 Jupyter 中使用按钮修改变量的简洁方法
问题描述
我正在尝试使用 ipywidget 按钮来修改变量:
df = pd.DataFrame([['a','b'],['c','d']])
my_button = widgets.Button(description='Delete')
out = widgets.Output()
def on_button_clicked(_):
# "linking function with output"
with out:
# what happens when we press the button
df.to_clipboard()
df = pd.DataFrame(['t','x'],['y','z'])
print('hello' + str(len(df)))
my_button.on_click(on_button_clicked)
HBox([my_button])
我的目标是:
- 在剪贴板中获取 df 的值(我设法让它在某个时候工作,但在这种情况下不是,我不明白为什么)
- 将 df 修改为新值 ('t,x,y,z')
- 在按钮下方打印消息(或显示此结果的任何其他方法)
解决方案
推荐阅读
- augmented-reality - 有谁知道谷歌ARCore是否支持小米红米Note 10?
- typescript - 在开发模式下运行 Hyperledger Fabric Typescript 链码失败
- vba - 获取旋转动画的当前旋转状态
- javascript - jQuery .closest、.find 和 .toggleClass 到 vanilla javascript
- javascript - Solidity, Mocha AssertionError: Unspecified AssertionError
- php - 如何使用 PHP 从 websocket url [coincap.io] 获取数据?
- flutter - Dart 简化空值的方法调用
- firebase - 如何从本地运行的 python 脚本访问 firestore 数据?
- python - 在pygame中移动矩形
- php - 当输入名称不是静态时,PHP 表单循环将变量传递给 $_POST