Let's say this is my dataframe:
and the user inputs B and 2
Then the function would return clemintine
Is there a way to do this without using a bunch of if elif statements. The actual dataframe I'm working with is much larger and it would take a long time to do with if elif statements.
Essentially I want the user to enter a row index value and a column index value and the function returns the corresponding value.
If you define you row starting value as 0 then you can achieve this by the following code
import pandas as pd# define sample data frame
df = pd.DataFrame({'A': ['Apple', 'Pear', 'Strawberry'],'B': ['Banana', 'Clementine', 'Blackberry'],'C': ['Strawberry', 'Blackberry', 'Peach']})# get user input
selected_row = int(input('Please enter the row that you want to specify: '))
selected_column = input('Please enter the column that you want to specify: ')# return value
cell_value = df[selected_column].iloc[selected_row]print(cell_value)