在 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/