Here is a simple snippet for analysing person-level means for Workplace Analytics metrics using `pandas`.
This example is based on running Python via R and the `reticulate` R package, so the data is actually passed on to `our_data_py` from the object `r.our_data`, but this can be imported using a CSV file.
import pandas as pd
import dateutil
our_data_py = r.our_data
# our_data_py.head()
# our_data_py.shape
our_data_py.info()
We can do a bit of analysis with it. Let's start with changing the date:
our_data_py['Date'] = our_data_py['Date'].apply(dateutil.parser.parse, dayfirst = True)
our_data_py['Date'].describe()
The next step is to create a function that aggregates metrics at the person and org level:
def analyse_metric(data, metric, hrvar):
data = data.groupby(['PersonId',hrvar])
data = data[metric].mean()
data = data.reset_index()
data = data.groupby(hrvar)
output = data[metric].mean()
return output
analyse_metric(our_data_py, metric = 'Collaboration_hours', hrvar = 'LevelDesignation')