2

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:

  1. Part of Day
  2. Start time for Day Part
  3. End Time for Day Part

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!

1 Answer 1

4

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
Sign up to request clarification or add additional context in comments.

1 Comment

@PineNuts0 Click on the tick mark (not the triangles) below the triangles (which has a number in between) on the left of answer. Take a tour as well. stackoverflow.com/tour

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.