Reputation: 5234
I'm trying to create a dynamic user input form inside iPython / Jupyter 3. I want the user to be able to specify the following by entering things into input boxes:
After entering values into the input boxes I want the following data frame to be automatically created.
Here is an example:
Day-Part Start Time End Time
Morning 6:00 09:59
Lunch 10 12:59
Afternoon Rush 13:00 15:50
Evening 22:00 24:00
The tricky part is this all needs to be dynamic. I need the user to be able to specify any number of "Day-Parts". For example a user can only have two day parts with start and end times for each or 15 day parts with start and end times for each.
Whatever the user ends up inputting, needs to be turned into a data frame for my later code to ingest.
*Any help is greatly appreciated!
Upvotes: 2
Views: 14926
Reputation: 17074
You can implement something like this:
import pandas as pd
df = pd.DataFrame(columns=["Day-Part", "Start Time", "End Time"])
parts = int(raw_input("Enter the number of day parts:"))
for _ in range(parts):
dp = raw_input("Enter Part of the Day ")
st = raw_input("Enter start time for {}".format(dp))
et = raw_input("Enter end time for {}".format(dp))
df1 = pd.DataFrame(data=[[dp,st,et]],columns=["Day-Part", "Start Time", "End Time"])
df = pd.concat([df,df1], axis=0)
df.index = range(len(df.index))
print df
Upvotes: 4