User input shows value in other data frame column

I am trying to get the value of a corresponding cell in an adjacent column to show it's value after a user puts in a variable.

Example of the data frame:

Price Cap
0 2.5 8.5032
1 3.0 7.1208
2 3.5 5.9551
3 4.0 4.9444
4 4.5 5.2753
5 5.0 4.2754

Prompt the user for price and have it return the corresponding value in the Cap column.

The problem I am getting are the results are returning Empty DataFrame when I'm expecting a float value from the Cap column.

Example: Input Price: 3.0 Cap: 7.1208

The data is being pulled from a csv and not created within the code; if that matters. Cap column has been converted to float data type from string value. I've tried to leave the Cap column data as a string and the results still fail. Created Data Frame is labeled pdfrm

Example Code:
    import numpy as np  
    import pandas as pd 

    prices = "/Users/Me/Desktop/file.csv"   

    pdfrm = pd.read_csv(prices)         

    pdfrm.drop(['Column3','Column4','Column5'],axis = 1, inplace = True)        
    pdfrm.fillna(0, inplace = True)                         
    pdfrm.columns.str.replace(' ','')   
    pdfrm.rename(columns={'Column1':'Price', 'Column2':'Cap'}, inplace=True)    
    pdfrm['Cap'] = pdfrm['Cap'].str.replace('%','')             
    pdfrm['Cap'] = pdfrm['Cap'].astype('float') / 100               
    p = input('What is the price:')
    c = (pdfrm.loc[pdfrm['Cap'] == p])
    print('Cap:',c)

or

    p = input('What is the price:')
    c = (pdfrm.loc[pdfrm['Price'] == p])
    print('Cap:',c)
Results:
    What is the price:3.0
    Cap: Empty DataFrame
    Columns: [Price, Cap]
    Index: []

What I am looking for is:

    What is the price:3.0
    Cap:7.1208

I've removed all NaN values and replaced them with 0.00. All white space has been removed from within the data frame.

Overall the data frame is a two column, 39 row data set that will constantly change and I'm not sure if the code I'm running that specifically needs user input would accomplish what I am looking for.

I'm open to all suggestions.



Comments

Popular posts from this blog

Today Walkin 14th-Sept

Spring Elasticsearch Operations

Hibernate Search - Elasticsearch with JSON manipulation