How to find a value entered by user in a dataframe in python

Viewed 29

I'm trying to do this for our assignment. We are only allowed to use pandas, numpy and basic python and we had to do this by accessing our uni timetable which is an excel file and has 5 separate sheets. If we cannot use loc function in data frames how do we do this? Also how do you find the least populated rows? I'm either getting a lot of errors or i can't find any way to solve these problems.

  1. Read the Timetable Using Pandas.
  2. Remove Un necessary Top Rows using pandas.
  3. Return all the classes of the particular subject (Ask from User) along with Time, Day and Room Number.
  4. Ask the list of Subjects from user and return the classes the of these subjects along with Time, Day and Room Number.
  5. Return the Empty slots of the given Day (Monday, Tuesday, Wednesday, Thursday, Friday).
  6. Which Classroom is less busy in overall week.
  7. Which Lab is the busiest lab in the overall week, return its name.

Here is my code:

import pandas as pd
import numpy as np

#accessing excel file
path = (r'C:\Users\user\Downloads\TimeTable, FSC, Fall-2022.xlsx')

data = pd.read_excel(path,sheet_name=None)
df = pd.concat(data[frame] for frame in data.keys())

#allocating variables(names of days) to their respective file paths
mon = pd.read_excel(path,sheet_name = "Monday")
tues = pd.read_excel(path,sheet_name = "Tuesday")
wed = pd.read_excel(path,sheet_name = "Wednesday")
thur = pd.read_excel(path,sheet_name = "Thursday")
fri = pd.read_excel(path,sheet_name = "Friday")
#timetable.head()

#creating a dictionary that has access to (names of days) variables -- a dictionary for the timetable of whole week
empty_dictionary = {}
timetable = {
        "Monday" : mon,
       "Tuesday" : tues,
        "Wednesday" : wed,
        "Thursday" : thur,
        "Friday" : fri,
    }


#dropping unnecessary rows from all sheets (not dropping 0th row because dropping it removes the name of day from the top left corner)
mon.drop([1,2], axis = 0, inplace = True)
tues.drop([1,2], axis = 0, inplace = True)
wed.drop([1,2], axis = 0, inplace = True)
thur.drop([1,2], axis = 0, inplace = True)
fri.drop([1,2], axis = 0, inplace = True)
mon.head()

#This part is not working
df.loc[df[timetable(['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday'])==subject]]
df.loc[df["Monday"]==subject]

#Part 3 of question
#asking user to enter the subject name

subject = str(input("Enter the subject you want to search classes for: "))
0 Answers
Related