Dec-28-2023, 09:59 PM
(This post was last modified: Dec-28-2023, 09:59 PM by deanhystad.)
I have no idea what you are trying to do. I see you have a similar post that "works well".
https://python-forum.io/thread-41339.html
The problem is that if you are using the inquirer package the code that "works well" doesn't run at all. Not even close.
https://python-inquirer.readthedocs.io/en/latest/
I looked at the documentation and checkbox() doesn't have "invalid_message" or "instruction" arguments. The validate lambda is not valid because the validate function is passed two arguments. checkbox() returns a list of the selected items and lists don't support execute().
If I fix all that, there is still the problem that you cannot pass a Pandas series as the list of choices to checkbox().
The example below fixes all the problems:
https://python-forum.io/thread-41339.html
The problem is that if you are using the inquirer package the code that "works well" doesn't run at all. Not even close.
https://python-inquirer.readthedocs.io/en/latest/
I looked at the documentation and checkbox() doesn't have "invalid_message" or "instruction" arguments. The validate lambda is not valid because the validate function is passed two arguments. checkbox() returns a list of the selected items and lists don't support execute().
If I fix all that, there is still the problem that you cannot pass a Pandas series as the list of choices to checkbox().
m_list = df.columns # columns is a series. Is not a valid type to use as choices to checkbox. return m_listAnd when I fix that, I still have this problem:
def get_e(): m_c = get_m_g()This function draws the checkboxes, but it throws away the results. m_c is local to the function get_e(), and only exists while the function executes. There is no way for you to get the user selections.
The example below fixes all the problems:
import inquirer import pandas as pd def validate(answers, current): """Can only check 1 or 2 boxes.""" return 0 < len(current) < 3 def select_columns(columns, prompt="Select"): return inquirer.checkbox(message=prompt, choices=columns, validate=validate) def main(): df = pd.read_excel("data.xlsx") columns = select_columns(list(df.columns), "Choose columns to display") print(df[columns]) if __name__ == "__main__": main()