Redirect dataframe table from selections from selectbox

I have a dataframe table of call and put options, Iā€™ve added a selectbar for I can select the expiration dates but I am having trouble for it to show the data for selected date. Any help is very appreciated!

Hi @Always_Flow,

Thanks for posting!

Can you share the code youā€™ve written to implement this so far?

Caroline :balloon:

Untitled 2
iā€™m using yahoo_fin api to get data, above iā€™ve put the photo of line of code that is allowing me to see data and it works fine, just quite havenā€™t figured out how to match the selectbox expiration with the presentation of dataframe table.

I suppose that callData is dataframe with a column expiration_date.
so, try

st.dataframe( callData[callData['expiration_date']==option])


this is what the dataframe contains, iā€™ve attempted to use: st.dataframe(callData[callData[ā€˜Contract Nameā€™]==option])
but the result shows nothing on the table.
Also thank you so much for your assistance iā€™m still fairly new to coding as I started 2 months ago haha.

What are the options of the selectbox?
In your your first post, you were asking to filter by ā€˜expiration dateā€™ but now you are filtering by ā€˜Contract Nameā€™. Your options must fit with values of the selected column.

ahhh i see i also attempted what you recommended but it isnā€™t in the columnā€¦ these are my options on the select box i have created


Untitled2
on the line of code I am showing above is the way i get the option chain data, will i have to change the options in my select box to be able to see different dated contracts?

Your selectbox options should be populated from the relevant column of the dataframe.

option = st.selectbox('Choose expiration date', callData['Last Trade Date'].unique())

st.dataframe( callData[callData['Last Trade Date']==option])

This should work according to what you have sent.

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.