pyds_learner
pyds_learner

Reputation: 519

select appropriate dataframe based on user input

I have the below data frames loaded :

  1. df_1000-2000
  2. df_3000-4000
  3. df_5000-6000
  4. df_7000-8000

Now I get a user input value as 1000-2000. Based on the user input value I need to work on respective data frame. In this case, I need to work on : df_1000-2000

How to select the data frame dynamically based on user input and start working on it ?

Upvotes: 0

Views: 291

Answers (1)

jpp
jpp

Reputation: 164783

Use a dictionary

You should restructure how you store and access your dataframes. First define a dictionary:

dfs = {'1000-2000': df_1000-2000, '3000-4000': df_3000-4000, etc.}

Then taking a user input and using it to query your dictionary is straightforward:

value = input('Input the range you require, e.g. 1000-2000:')
res = dfs[value]

Upvotes: 1

Related Questions