Home > OS >  How to add a checkbox in pandas dataframe
How to add a checkbox in pandas dataframe

Time:10-29

I have created a dataframe as:

import pandas as pd
 
data = [['Ankit'], ['Akshat' ]]
 
df = pd.DataFrame(data, columns = ['Name'])

Now, I want to insert a column PPA which has checkbox button as values. So, I have written the code as:

import ipywidgets
checkbox_button=widgets.Checkbox(description="", value=False,indent=False)
df.insert(loc = 0,column = 'PPA',value = checkbox_button)

But after running the code in jupyter notebook, I am getting the column values of column PPA as:
Checkbox(value=False, indent=False) but when I run widgets.Checkbox(description="", value=False,indent=False) in the jupyter notebook, I get the proper checkbox button.

So, Can anyone please tell me how to get the checkbox button in a column of a dataframe ?
Any help would be appreciated.

CodePudding user response:

I wouldn't recommend, but you can mix html code to in your data, then use df.style to render the HTML:

df = pd.DataFrame([[1,2],[3,4]], columns=['a','b'])
df.insert(loc = 0,column = 'PPA',value = '<input type="checkbox" />')
df.style

Output:

enter image description here

which you can interact with individual checkbox.

  • Related