Return single value from a dataframe as a number

Viewed 19

I have the following dataframe:

df = pd.DataFrame(index=["daily", "weekly", "monthly", "yearly", "daily_w"], data={'Multiple':[365, 52, 12, 1, 260]})

I want to feed it a variable and have it return the number:

choice = "daily"

I expect the result as a number 365

I have tried things like:

s = df.loc[choice] and then b = s.iloc[0,0], but this returns an unusable series

There must be a very easy one-liner to return a simple number?

Thank you in advance.

1 Answers

If need select by index and column Multiple use DataFrame.loc with second argument column name:

s = df.loc[choice, 'Multiple']
print (s)
365
Related