0

I am building a model that requires different input values according to the type of building. I have a data frame with the data of the buildings. In a simplified form:

df = pd.DataFrame([[ 'House', 0.17, 0.3], 
[ 'Hotel', 0.43, 0.23], 
[ 'Restaruant', 0.61, 0.34], 
[ 'Office', 0.49, 0.12], 
[ 'School', 0.37, 0.53]], columns=('Building', 'Probability 1', 'Probability 2'))

In another script I have the input values for the building so that the return value is linked to the building chosen. I need to use the Probability 1 value in the above dataframe in another script.

How can I look for the input value in the dataframe and use that probability in another script?

Eg. return the Probability 1 of an Office building.

Thank you very much!

2 Answers 2

1

I don't know if I understand it correctly. But assuming you want the Probability 1 column and the buildingtype is a variable. Then this would suffice I guess.

building = 'Office'
df[df.Building==building]['Probability 1'].values[0]

Look where the values of the Building column are equal to the building parameter. Then we only need the column 'Probability 1', use values. This returns an array of length 1. Here we need the first element (only element).

Sign up to request clarification or add additional context in comments.

Comments

0

Convert Building column to index, so possible use DataFrame.loc for selecting:

df = df.set_index('Building')

out = df.loc['Office','Probability 1']

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.