Package: treets
TREETS#hidefromtreetsimport*Installpip install treetsExample for a quick data analysis on phased studies.importtreets.coreastreetsimportpandasaspdTake a brief look on the food logging dataset and the reference
information sheettreets.file_loader('data/col_test_data/yrt*').head(2)<style scoped>
    .dataframe tbody tr th:only-of-type {
        vertical-align: middle;
    }.dataframe tbody tr th {
    vertical-align: top;
}

.dataframe thead th {
    text-align: right;
}</style>Unnamed: 0original_logtimedesc_textfood_typePID002021-05-12 02:30:00 +0000Milkbyrt1999112021-05-12 02:45:00 +0000Some Medicationmyrt1999pd.read_excel('data/col_test_data/toy_data_17May2021.xlsx').head(2)<style scoped>
    .dataframe tbody tr th:only-of-type {
        vertical-align: middle;
    }.dataframe tbody tr th {
    vertical-align: top;
}

.dataframe thead th {
    text-align: right;
}</style>mCC_IDParticipant_Study_IDStudy PhaseIntervention group (TRE or HABIT)Start_DayEnd_dayEating_Window_StartEating_Window_End0yrt19992S-REMTRE2021-05-122021-05-1400:00:0023:59:001yrt19992T3-INTTRE2021-05-152021-05-1808:00:0018:00:00Call summarize_data_with_experiment_phases() function to make the table
that contains analytic information that we want.df=treets.summarize_data_with_experiment_phases(treets.file_loader('data/col_test_data/yrt*')\,pd.read_excel('data/col_test_data/toy_data_17May2021.xlsx'))Participant yrt1999 didn't log any food items in the following day(s):
2021-05-18
Participant yrt2000 didn't log any food items in the following day(s):
2021-05-12
2021-05-13
2021-05-14
2021-05-15
2021-05-16
2021-05-17
2021-05-18
Participant yrt1999 have bad logging day(s) in the following day(s):
2021-05-12
2021-05-15
Participant yrt1999 have bad window day(s) in the following day(s):
2021-05-15
2021-05-17
Participant yrt1999 have non adherent day(s) in the following day(s):
2021-05-12
2021-05-15
2021-05-17df<style scoped>
    .dataframe tbody tr th:only-of-type {
        vertical-align: middle;
    }.dataframe tbody tr th {
    vertical-align: top;
}

.dataframe thead th {
    text-align: right;
}</style>mCC_IDParticipant_Study_IDStudy PhaseIntervention group (TRE or HABIT)Start_DayEnd_dayEating_Window_StartEating_Window_Endphase_durationcaloric_entries_num...logging_day_counts%_logging_day_countsgood_logging_days%_good_logging_daysgood_window_days%_good_window_daysoutside_window_days%_outside_window_daysadherent_days%_adherent_days0yrt19992S-REMTRE2021-05-122021-05-1400:00:0023:59:003 days7...3100.0%2.066.67%3.0100.0%0.00.0%2.066.67%1yrt19992T3-INTTRE2021-05-152021-05-1808:00:0018:00:004 days8...375.0%2.050.0%1.025.0%2.050.0%1.025.0%2yrt20003T3-INTTRE2021-05-122021-05-1408:00:0016:00:003 days0...00.0%0.00.0%0.00.0%0.00.0%0.00.0%3yrt20003T3-INTTRE2021-05-152021-05-1808:00:0016:00:004 days0...00.0%0.00.0%0.00.0%0.00.0%0.00.0%4yrt20014T12-ATRENaTNaTNaNNaNNaT0...0nan%NaNNaNNaNNaNNaNNaNNaNNaN5 rows × 32 columnsLook at resulting statistical information for the first row in the
resulting dataset.df.iloc[0]mCC_ID                                           yrt1999
Participant_Study_ID                                   2
Study Phase                                        S-REM
Intervention group (TRE or HABIT)                    TRE
Start_Day                            2021-05-12 00:00:00
End_day                              2021-05-14 00:00:00
Eating_Window_Start                             00:00:00
Eating_Window_End                               23:59:00
phase_duration                           3 days 00:00:00
caloric_entries_num                                    7
medication_num                                         0
water_num                                              0
first_cal_avg                                   5.916667
first_cal_std                                   2.240722
last_cal_avg                                   19.666667
last_cal_std                                   12.933323
mean_daily_eating_window                           13.75
std_daily_eating_window                        11.986972
earliest_entry                                       4.5
2.5%                                              4.5375
97.5%                                            27.5625
duration mid 95%                                  23.025
logging_day_counts                                     3
%_logging_day_counts                              100.0%
good_logging_days                                    2.0
%_good_logging_days                               66.67%
good_window_days                                     3.0
%_good_window_days                                100.0%
outside_window_days                                  0.0
%_outside_window_days                               0.0%
adherent_days                                        2.0
%_adherent_days                                   66.67%
Name: 0, dtype: objectExample for a quick data analysis on non-phased studies.take a look at the original datasetdf=treets.file_loader('data/test_food_details.csv')df.head(2)<style scoped>
    .dataframe tbody tr th:only-of-type {
        vertical-align: middle;
    }.dataframe tbody tr th {
    vertical-align: top;
}

.dataframe thead th {
    text-align: right;
}</style>Unnamed: 0IDunique_coderesearch_info_iddesc_textfood_typeoriginal_logtimefoodimage_file_name013401477572733alqt14018795225150Waterw2017-12-08 17:30:00+00:00NaN11340148411111alqt14018795225150Coffee Whiteb2017-12-09 00:01:00+00:00NaNpreprocess the data to create features we might need in the furthur
analysis such as float time, week count since the first week, etc.df=treets.load_food_data(df,'unique_code','original_logtime',4)df.head(2)<style scoped>
    .dataframe tbody tr th:only-of-type {
        vertical-align: middle;
    }.dataframe tbody tr th {
    vertical-align: top;
}

.dataframe thead th {
    text-align: right;
}</style>Unnamed: 0IDunique_coderesearch_info_iddesc_textfood_typeoriginal_logtimedatefloat_timetimeweek_from_startyear013401477572733alqt14018795225150Waterw2017-12-08 17:30:00+00:002017-12-0817.50000017:30:001201711340148411111alqt14018795225150Coffee Whiteb2017-12-09 00:01:00+00:002017-12-0824.01666700:01:0012017Call summarize_data() function to make the table that contains analytic
information that we want.¶df=treets.summarize_data(df,'unique_code','float_time','date')df.head(2)<style scoped>
    .dataframe tbody tr th:only-of-type {
        vertical-align: middle;
    }.dataframe tbody tr th {
    vertical-align: top;
}

.dataframe thead th {
    text-align: right;
}</style>unique_codenum_daysnum_total_itemsnum_f_n_bnum_medicationsnum_waterfirst_cal_avgfirst_cal_stdlast_cal_avglast_cal_stdeating_win_avgeating_win_stdgood_logging_countfirst_cal variation (90%-10%)last_cal variation (90%-10%)2.5%95%duration mid 95%0alqt1148284857131499619347.8217956.71071723.4858974.86908215.6641038.2312011462.9666679.6666674.53500026.81333322.6366671alqt1401879522564488484317.5257815.43456325.8585943.37483918.3328136.60391348413.4500003.1000004.18333327.43833323.416667Look at resulting statistical information for the first row in the
resulting dataset.df.iloc[0]unique_code                      alqt1148284857
num_days                                     13
num_total_items                             149
num_f_n_b                                    96
num_medications                              19
num_water                                    34
first_cal_avg                          7.821795
first_cal_std                          6.710717
last_cal_avg                          23.485897
last_cal_std                           4.869082
eating_win_avg                        15.664103
eating_win_std                         8.231201
good_logging_count                          146
first_cal variation (90%-10%)          2.966667
last_cal variation (90%-10%)           9.666667
2.5%                                      4.535
95%                                   26.813333
duration mid 95%                      22.636667
Name: 0, dtype: objectClean text in food loggings# import the datasetdf=treets.file_loader('data/col_test_data/yrt*')df.head(3)<style scoped>
    .dataframe tbody tr th:only-of-type {
        vertical-align: middle;
    }.dataframe tbody tr th {
    vertical-align: top;
}

.dataframe thead th {
    text-align: right;
}</style>Unnamed: 0original_logtimedesc_textfood_typePID002021-05-12 02:30:00 +0000Milkbyrt1999112021-05-12 02:45:00 +0000Some Medicationmyrt1999222021-05-12 04:45:00 +0000bacon eggfyrt1999treets.clean_loggings(df,'desc_text','PID').head(3)<style scoped>
    .dataframe tbody tr th:only-of-type {
        vertical-align: middle;
    }.dataframe tbody tr th {
    vertical-align: top;
}

.dataframe thead th {
    text-align: right;
}</style>PIDdesc_textcleaned0yrt1999Milk[milk]1yrt1999Some Medication[medication]2yrt1999bacon egg[bacon, egg]We can see that words are lower cased, modifiers are removed(2nd row)
and items are split into individual items(third row).Visualizations# import the datasetdf=treets.file_loader('data/test_food_details.csv')df.head(2)<style scoped>
    .dataframe tbody tr th:only-of-type {
        vertical-align: middle;
    }.dataframe tbody tr th {
    vertical-align: top;
}

.dataframe thead th {
    text-align: right;
}</style>Unnamed: 0IDunique_coderesearch_info_iddesc_textfood_typeoriginal_logtimefoodimage_file_name013401477572733alqt14018795225150Waterw2017-12-08 17:30:00+00:00NaN11340148411111alqt14018795225150Coffee Whiteb2017-12-09 00:01:00+00:00NaNmake a scatter plot for people’s breakfast time# create required features for function first_cal_mean_with_error_bar()df['original_logtime']=pd.to_datetime(df['original_logtime'])df['local_time']=treets.find_float_time(df,'original_logtime')df['date']=treets.find_date(df,'original_logtime')# call the functiontreets.first_cal_mean_with_error_bar(df,'unique_code','date','local_time')Use swarmplot to visualize each person’s eating time distribution.treets.swarmplot(df,50,'unique_code','date','local_time')