I have created a date_input widget in my streamlit app where the user can select a specific date. Based on this date, a dataframe will be sliced and presented to the user.
The problem is that when the user selects, for example, 2020/09/14 as startdate, streamlit will output the following error:
TypeError: ‘<’ not supported between instances of ‘str’ and 'Timestamp’
Can you provide the code you are running that demonstrates the error? I suspect this is actually a pandas issue where pandas wants you to convert your string to a timestamp, but without seeing the code I’m just guessing.
# Here I create the date_input objects
start_date = st.sidebar.date_input('Start Date')
end_date = st.sidebar.date_input('Eind Date')
# The start_date and end_date will be input for the foillowing function
def SearchPortfolio(data, start_date, eind_date):
# Slice the data with the end date and start date and extract certain values for the output dataframe.
df = data.loc[start_date:eind_date]
portf_startvalue = df.loc[start_date,['Start Waarde']][0]
portf_stortingen = df.loc[start_date:eind_date,['Stortingen']].sum()[0]
portf_deponeringen = df.loc[start_date:eind_date,['Deponeringen']].sum()[0]
portf_onttrekkingen = df.loc[start_date:eind_date,['Onttrekkingen']].sum()[0]
portf_lichtingen = df.loc[start_date:eind_date,['Lichtingen']].sum()[0]
portf_endvalue = df.loc[eind_date,['Eind Waarde']][0]
overview = [portf_startwaarde, portf_stortingen, portf_deponeringen, portf_onttrekkingen, portf_lichtingen,
portf_eindwaarde]
df_final = pd.DataFrame([overview], columns = ['Start Waarde', 'Stortingen', 'Deponeringen', 'Onttrekkingen', 'Lichtingen', 'Eind Waarde'])
return df_final
Could this possibly be a typo problem? Your second date_input widget writes to end_date, but in the pandas portion of the code, you are referring to eind_date.
I figured out what the problem is.
the Date_input widget returns a timestamp and this gives an error because in my data I do not have the timestamp, only date.
I fixed this by converting the date with strftime(%Y-%M-%D) method. Now it outputs the correct date form and the data can be sliced correctly. Thanks for your input.
Thanks for stopping by! We use cookies to help us understand how you interact with our website.
By clicking “Accept all”, you consent to our use of cookies. For more information, please see our privacy policy.
Cookie settings
Strictly necessary cookies
These cookies are necessary for the website to function and cannot be switched off. They are usually only set in response to actions made by you which amount to a request for services, such as setting your privacy preferences, logging in or filling in forms.
Performance cookies
These cookies allow us to count visits and traffic sources so we can measure and improve the performance of our site. They help us understand how visitors move around the site and which pages are most frequently visited.
Functional cookies
These cookies are used to record your choices and settings, maintain your preferences over time and recognize you when you return to our website. These cookies help us to personalize our content for you and remember your preferences.
Targeting cookies
These cookies may be deployed to our site by our advertising partners to build a profile of your interest and provide you with content that is relevant to you, including showing you relevant ads on other websites.