python - 如何显示包含本地 Python 函数可点击链接的 Pandas 单元格?

标签 python pandas jupyter-notebook click

在 Jupyter 笔记本中,如何显示 pandas 单元格,该单元格显示可点击的链接,允许触发对常规 Python 函数的调用?

例如,在下面的数据框中,我希望能够手动单击Process列的给定行来触发process_item(item) Python功能:

   Item  Process
0  foo   click_here_to_process
1  bar   click_here_to_process

def process_item(item):
    ...

最佳答案

我不确定是否可以以交互方式完成,但这是您可以在数据框中存储和调用函数的方法。

import pandas as pd

def hello(parameter): # Some custom function 
    print(parameter)
    return

variable = hello # assign the function to a variable
data = {'col_1': [3, 2, 1, 0], 'col_2': [variable,variable,variable,variable]}
df = pd.DataFrame.from_dict(data)

df['col_2'][1]("hello World") #here we are calling the function with parameters

关于python - 如何显示包含本地 Python 函数可点击链接的 Pandas 单元格?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60015676/

相关文章:

python - 在 Python 中制作唯一对象列表

python - 如何提取python代码文件中使用的函数?

python - XOR Python 文本加密/解密

python - .Between 函数未按预期工作

python - Pandas — 在 MultiIndex 上使用部分切片设置值

windows - 在端口 8888 上找不到 Jupyter Notebook 服务器 (Windows 10)

python - 是否可以在没有轴的情况下向绘图添加另一个值?

python - 在 Jupyter Windows 上使用池并行读取多个文件需要很长时间 :

python - 在 Django 的一个 View 中组合来自三个表的数据

python - 使用 Matplotlib 绘制日内 OHLC 图表的问题