Skip to main content
edited body; edited title
Source Link
MarianD
  • 14.4k
  • 12
  • 50
  • 61

How to get value of callcell in dataframe

I'm new to pythonPython, so please be lenient.

I want to read the value of a single cell from a dataframe based on the selected row. I do this as below, but I get the value not when I click on a record (when the selection checkbox is checked), but only after I click on another one or uncheck the row. Why?

I get some record from the database and draw a table using Streamlit and pandas:

employees = get_all_employees()
event = st.dataframe(
    employees,
    hide_index=True,
    selection_mode="single-row",
    on_select=on_employee_select,
)

Then the on_select function goes like this:

def on_employee_select():
    global selected_emp_id, selected_emp_name
    row = event.selection.rows  # type: ignore # List of selected row indices
    if row:
        selected_emp_id = int(employees.iat[row[0], 0]) # type: ignore
        selected_emp_name = str(employees.iat[row[0], 1]) # type: ignore
    else:
        selected_emp_id = 0
        selected_emp_name = ""
    st.write("on_employee_select: ", selected_emp_id, selected_emp_name)

How should it be done?

How to get value of call in dataframe

I'm new to python, so please be lenient.

I want to read the value of a single cell from a dataframe based on the selected row. I do this as below, but I get the value not when I click on a record (when the selection checkbox is checked), but only after I click on another one or uncheck the row. Why?

I get some record from the database and draw a table using Streamlit and pandas:

employees = get_all_employees()
event = st.dataframe(
    employees,
    hide_index=True,
    selection_mode="single-row",
    on_select=on_employee_select,
)

Then the on_select function goes like this:

def on_employee_select():
    global selected_emp_id, selected_emp_name
    row = event.selection.rows  # type: ignore # List of selected row indices
    if row:
        selected_emp_id = int(employees.iat[row[0], 0]) # type: ignore
        selected_emp_name = str(employees.iat[row[0], 1]) # type: ignore
    else:
        selected_emp_id = 0
        selected_emp_name = ""
    st.write("on_employee_select: ", selected_emp_id, selected_emp_name)

How should it be done?

How to get value of cell in dataframe

I'm new to Python, so please be lenient.

I want to read the value of a single cell from a dataframe based on the selected row. I do this as below, but I get the value not when I click on a record (when the selection checkbox is checked), but only after I click on another one or uncheck the row. Why?

I get some record from the database and draw a table using Streamlit and pandas:

employees = get_all_employees()
event = st.dataframe(
    employees,
    hide_index=True,
    selection_mode="single-row",
    on_select=on_employee_select,
)

Then the on_select function goes like this:

def on_employee_select():
    global selected_emp_id, selected_emp_name
    row = event.selection.rows  # type: ignore # List of selected row indices
    if row:
        selected_emp_id = int(employees.iat[row[0], 0]) # type: ignore
        selected_emp_name = str(employees.iat[row[0], 1]) # type: ignore
    else:
        selected_emp_id = 0
        selected_emp_name = ""
    st.write("on_employee_select: ", selected_emp_id, selected_emp_name)

How should it be done?

Add framework tag. Remove tag from title.
Link
wjandrea
  • 33.9k
  • 10
  • 69
  • 105

how How to get value of call in dataframe (pandas)

Source Link

how to get value of call in dataframe (pandas)

I'm new to python, so please be lenient.

I want to read the value of a single cell from a dataframe based on the selected row. I do this as below, but I get the value not when I click on a record (when the selection checkbox is checked), but only after I click on another one or uncheck the row. Why?

I get some record from the database and draw a table using Streamlit and pandas:

employees = get_all_employees()
event = st.dataframe(
    employees,
    hide_index=True,
    selection_mode="single-row",
    on_select=on_employee_select,
)

Then the on_select function goes like this:

def on_employee_select():
    global selected_emp_id, selected_emp_name
    row = event.selection.rows  # type: ignore # List of selected row indices
    if row:
        selected_emp_id = int(employees.iat[row[0], 0]) # type: ignore
        selected_emp_name = str(employees.iat[row[0], 1]) # type: ignore
    else:
        selected_emp_id = 0
        selected_emp_name = ""
    st.write("on_employee_select: ", selected_emp_id, selected_emp_name)

How should it be done?

created from staging ground