I have a dataframe that has a column 'Time'
in seconds:
Time
1
2
3
4
I want the user to input the date with a timestamp (eg format: 25/09/2022 12:30:00
). Then, I need to add a new column ‘DateTime’ which combines the user input datetime with my 'Time'
column. The 'DateTime'
column should look like this:
DateTime
25/09/2022 12:30:01
25/09/2022 12:30:02
25/09/2022 12:30:03
25/09/2022 12:30:04
I managed to do this in python, where the user input is on the terminal.
My python code (without Streamlit):
start_date = input(‘Please enter start date and time!’)
the user input ex: 25/05/2022 06:00:00
Then I run this line to combine this user input with my 'Time'
column to achieve 'DateTime'
column in the above format:
df[‘DateTime’] = pd.to_datetime(start_date) + pd.to_timedelta(df[‘Time’], unit=‘s’)
However, I would like to have this on Streamlit. From the documentation, there is currently no possibility to input date with a timestamp in Streamlit, unless you enter them separately, as follows:
start_date = st.date_input('Enter start date', value=datetime.datetime(2019,7,6))
start_time = st.time_input('Enter start time', datetime.time(8, 45))
So, this gives the user the possibility to enter the date and time separately, however I don’t know how to derive my ‘DateTime’ column and add it to the df. Appreciate any advice on how to accomplish this.