write st python code to do: 1-fist show df 2-then get searchword as input 3-when button…
- User
write st python code to do: 1-fist show df 2-then get search_word as input 3-when button pressed find search_word in whole df 4-show filtered_df as output
Assistant
Here is the Python code to do that:
pythonimport pandas as pd # Sample dataframe df = pd.DataFrame({'Col1': [1, 2, 3], 'Col2': ['hello', 'world', 'python']}) print('Original DataFrame:') print(df) search_word = input("Enter the search word: ") def filter_df(): global df filtered_df = df[df.apply(lambda row: row.astype(str).str.contains(search_word).any(), axis=1)] print('Filtered DataFrame with word "'+search_word+'":') print(filtered_df) # Call filter_df function on button click filter_df()
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.