Jovian
⭐️
Sign In
In [2]:
!pip install jovian --upgrade --quiet
In [3]:
project_name='sessions'

Import Data And Libraries

In [4]:
import numpy as np 
import pandas as pd 
import datetime
import os
import matplotlib.pyplot as plt
import seaborn as sns
%matplotlib inline
In [5]:
from google.colab import files
data_to_load = files.upload()
Saving sessions_01_2021.xlsx to sessions_01_2021.xlsx
In [6]:
import io
df = pd.ExcelFile(io.BytesIO(data_to_load['sessions_01_2021.xlsx']))
In [7]:
df.sheet_names
Out[7]:
['Sheet1']

Exploratory Data Analysis (EDA)

In [8]:
data=df.parse(sheet_name="Sheet1")
data.head()
Out[8]:

We should drop all the columns containing the irrelevant days for the shifts (Tuesdats, Thursdays, Fridays, Saturdays)

In [15]:
data=data[data.columns.drop(list(data.filter(regex='Tue')))]
data=data[data.columns.drop(list(data.filter(regex='Thu')))]
data=data[data.columns.drop(list(data.filter(regex='Fri')))]
data=data[data.columns.drop(list(data.filter(regex='Sat')))]
data.head()
Out[15]:
In [18]:
# The column on the right is not relevant
data=data.drop(columns=['לא ססיה 1\r\nכן ססיה 3'])
data.head()
--------------------------------------------------------------------------- KeyError Traceback (most recent call last) <ipython-input-18-591391c46ed3> in <module>() 1 # The column on the right is not relevant ----> 2 data=data.drop(columns=['לא ססיה 1\r\nכן ססיה 3']) 3 data.head() /usr/local/lib/python3.6/dist-packages/pandas/core/frame.py in drop(self, labels, axis, index, columns, level, inplace, errors) 4172 level=level, 4173 inplace=inplace, -> 4174 errors=errors, 4175 ) 4176 /usr/local/lib/python3.6/dist-packages/pandas/core/generic.py in drop(self, labels, axis, index, columns, level, inplace, errors) 3887 for axis, labels in axes.items(): 3888 if labels is not None: -> 3889 obj = obj._drop_axis(labels, axis, level=level, errors=errors) 3890 3891 if inplace: /usr/local/lib/python3.6/dist-packages/pandas/core/generic.py in _drop_axis(self, labels, axis, level, errors) 3921 new_axis = axis.drop(labels, level=level, errors=errors) 3922 else: -> 3923 new_axis = axis.drop(labels, errors=errors) 3924 result = self.reindex(**{axis_name: new_axis}) 3925 /usr/local/lib/python3.6/dist-packages/pandas/core/indexes/base.py in drop(self, labels, errors) 5285 if mask.any(): 5286 if errors != "ignore": -> 5287 raise KeyError(f"{labels[mask]} not found in axis") 5288 indexer = indexer[~mask] 5289 return self.delete(indexer) KeyError: "['לא ססיה 1\\r\\nכן ססיה 3'] not found in axis"
In [20]:
#Change the name of the right column
data=data.rename(columns={"מס ססיות \r\nרצוי": "sessions_number"})
data.head()
Out[20]:
In [23]:
#row '0' is redundant
data=data.drop([0])
data.head()
Out[23]:

Looks nice, let's explore the data in depth, see if there is a need for more cleaning.

In [21]:
data.info()
<class 'pandas.core.frame.DataFrame'> RangeIndex: 23 entries, 0 to 22 Data columns (total 15 columns): # Column Non-Null Count Dtype --- ------ -------------- ----- 0 January 23 non-null object 1 Sun, 3 18 non-null float64 2 Mon, 4 18 non-null float64 3 Wed, 6 20 non-null float64 4 Sun, 10 20 non-null float64 5 Mon, 11 18 non-null float64 6 Wed, 13 17 non-null float64 7 Sun, 17 16 non-null float64 8 Mon, 18 15 non-null float64 9 Wed, 20 15 non-null float64 10 Sun, 24 16 non-null float64 11 Mon, 25 16 non-null float64 12 Wed, 27 19 non-null float64 13 Sun, 31 15 non-null float64 14 sessions_number 20 non-null float64 dtypes: float64(14), object(1) memory usage: 2.8+ KB
In [25]:
#print(data)
#is_NaN = data.isnull()
#row_has_NaN = is_NaN. any(axis=1)
#rows_with_NaN = data[row_has_NaN]
#print(rows_with_NaN)
In [26]:
data.head(23)
Out[26]:
In [36]:
#row '21' and '22' are totally empty, i should remove them, because these two residents are not working this month
data=data.drop([21, 22])
data.head(21)
Out[36]:
In [37]:
data.fillna(4)
Out[37]:

Understanding the data:

'1' - request to not have shift
'3' - request to have shift (prefers this day)
'4' - request to have shift
'sessions_number' - max number of shifts

Each day should have 2 residents

In [ ]:
jovian.commit(project=project_name, environment=None)
[jovian] Detected Colab notebook... [jovian] Please enter your API key ( from https://jovian.ai/ ): API KEY:
In [ ]:
 
In [ ]:
 
In [ ]: