@@ -45,19 +45,20 @@ def weight_distr(df, mode):
45
45
Create charts with overall and outlier weight distributions (included values only)
46
46
47
47
Parameters:
48
- df: (DataFrame) with subjid, param, measurement, age, sex, clean_value, clean_cat, include,
49
- category, colors, patterns, and sort_order columns
50
- mode: (str) indicates how many of the weights you want to use. If set to 'high', the function
51
- will only use weights above a certain threshold. Otherwise, it displays all the weights.
48
+ df: (DataFrame) with subjid, param, measurement, age, sex, clean_value, and
49
+ include columns
50
+ mode: (str) indicates how many of the weights you want to use. If set to 'high',
51
+ the function will only use weights above a certain threshold. Otherwise, it
52
+ displays all the weights.
52
53
"""
53
- wgt_grp = df [(df ["param" ] == "WEIGHTKG" ) & (df ["include" ] == True )]
54
+ wgt_grp = df [(df ["param" ] == "WEIGHTKG" ) & (df ["include" ] is True )]
54
55
if mode == "high" :
55
56
wgt_grp = wgt_grp .loc [wgt_grp ["measurement" ] >= 135 ]
56
57
plt .title ("Weights At or Above 135kg" )
57
58
else :
58
59
plt .title ("All Weights" )
59
60
if len (wgt_grp .index ) == 0 :
60
- print ("No included observations with weight (kg) >= 135" )
61
+ print ("No included observations with weight (kg) >= 135. " )
61
62
plt .close ()
62
63
else :
63
64
round_col = wgt_grp .apply (
@@ -66,7 +67,7 @@ def weight_distr(df, mode):
66
67
wgt_grp = wgt_grp .assign (round_weight = round_col .values )
67
68
wgt_grp_sum = wgt_grp .groupby ("round_weight" )["subjid" ].count ().reset_index ()
68
69
plt .rcParams ["figure.figsize" ] = [7 , 5 ]
69
- wgt_grp_sum_plot = plt .bar (wgt_grp_sum ["round_weight" ], wgt_grp_sum ["subjid" ])
70
+ plt .bar (wgt_grp_sum ["round_weight" ], wgt_grp_sum ["subjid" ])
70
71
# Assure there is some breadth to the x-axis in case of just a few observations
71
72
if wgt_grp ["measurement" ].max () - wgt_grp ["measurement" ].min () < 10 :
72
73
plt .xlim (wgt_grp ["measurement" ].min () - 5 , wgt_grp ["measurement" ].max () + 5 )
@@ -78,11 +79,12 @@ def weight_distr(df, mode):
78
79
79
80
def make_age_charts (df , mode ):
80
81
"""
81
- Creates a chart with the age ranges in the dataset. Counts the number of subjids in each range.
82
+ Creates a chart with the age ranges in the dataset. Counts the number of subjids in
83
+ each range.
82
84
83
85
Parameters:
84
- df: (DataFrame) with subjid, param, measurement, age, sex, clean_value, clean_cat, include,
85
- category, colors, patterns, and sort_order columns
86
+ df: (DataFrame) with subjid, param, measurement, age, sex, clean_value, clean_cat,
87
+ include, category, colors, patterns, and sort_order columns
86
88
mode: (str) indicates whether you want the adults or pediatrics values.
87
89
"""
88
90
obs_grp = df
@@ -94,8 +96,8 @@ def make_age_charts(df, mode):
94
96
else :
95
97
raise Exception ("Valid modes are 'adults' and 'pediatrics'" )
96
98
97
- # Adds label, color, pattern and sort order columns to the dataframe based on the age of each
98
- # row in the dataframe
99
+ # Adds label, color, pattern and sort order columns to the dataframe based on the
100
+ # age of each row in the dataframe
99
101
def add_categories_to_frame (df_data , df_reference ):
100
102
categories = []
101
103
colors = []
@@ -119,8 +121,8 @@ def add_categories_to_frame(df_data, df_reference):
119
121
# Call the categorizing function on the data
120
122
obs_grp = add_categories_to_frame (obs_grp , label_frame )
121
123
122
- # Groups the new dataframe by category, sort order, colors and patterns. It then counts the
123
- # number of subject ids in each group and sorts the values by sort order.
124
+ # Groups the new dataframe by category, sort order, colors and patterns. It then
125
+ # counts the number of subject ids in each group and sorts the values by sort order.
124
126
obs_grp = (
125
127
obs_grp .groupby (["category" , "sort_order" , "colors" , "patterns" ])["subjid" ]
126
128
.count ()
@@ -214,14 +216,14 @@ def overlap_view_adults(
214
216
xmin = math .floor (individual .age .min ())
215
217
xmax = math .ceil (individual .age .max ())
216
218
selected_param_plot .set_xlim (xmin , xmax )
217
- if include_carry_forward == True :
219
+ if include_carry_forward is True :
218
220
carry_forward = selected_param [
219
221
selected_param .clean_value == "Exclude-Carried-Forward"
220
222
]
221
223
selected_param_plot .scatter (
222
224
x = carry_forward .age , y = carry_forward .measurement , c = "c" , marker = "^"
223
225
)
224
- if include_percentiles == True :
226
+ if include_percentiles is True :
225
227
if param == "WEIGHTKG" :
226
228
percentile_df = wt_df
227
229
elif param == "BMI" :
@@ -287,7 +289,7 @@ def overlap_view_adults_show(
287
289
"""
288
290
Wraps overlap_view_adult with plt.show().
289
291
"""
290
- plot = overlap_view_adults (
292
+ overlap_view_adults (
291
293
obs_df ,
292
294
subjid ,
293
295
param ,
@@ -345,14 +347,14 @@ def overlap_view_pediatrics(
345
347
c = "r" ,
346
348
marker = "x" ,
347
349
)
348
- if include_carry_forward == True :
350
+ if include_carry_forward is True :
349
351
carry_forward = selected_param [
350
352
selected_param .clean_value == "Exclude-Carried-Forward"
351
353
]
352
354
selected_param_plot .scatter (
353
355
x = carry_forward .age , y = carry_forward .measurement , c = "c" , marker = "^"
354
356
)
355
- if include_percentiles == True :
357
+ if include_percentiles is True :
356
358
percentile_df = wt_df if param == "WEIGHTKG" else ht_df
357
359
percentile_window = percentile_df .loc [
358
360
(percentile_df .Sex == individual .sex .min ())
@@ -374,7 +376,7 @@ def overlap_view_pediatrics_show(
374
376
"""
375
377
Wraps overlap_view_pediatrics with plt.show().
376
378
"""
377
- plot = overlap_view_pediatrics (
379
+ overlap_view_pediatrics (
378
380
obs_df , subjid , param , include_carry_forward , include_percentiles , wt_df , ht_df
379
381
)
380
382
plt .show ()
@@ -442,7 +444,7 @@ def overlap_view_double_pediatrics(
442
444
ax2 .set_ylabel (
443
445
"weight (kg)" , color = color_secondary
444
446
) # we already handled the x-label with ax1
445
- if include_percentiles == True :
447
+ if include_percentiles is True :
446
448
percentile_window = wt_df .loc [wt_df .Sex == individual .sex .min ()]
447
449
ax2 .plot (percentile_window .age , percentile_window .P5 , color = "lightblue" )
448
450
ax2 .plot (
@@ -476,21 +478,21 @@ def overlap_view_double_pediatrics(
476
478
)
477
479
ax1 .plot (percentile_window_ht .age , percentile_window_ht .P95 , color = "pink" )
478
480
479
- if show_all_measurements == True :
481
+ if show_all_measurements is True :
480
482
ax1 .plot (height ["age" ], height ["measurement" ], color = color , label = "stature" )
481
483
ax2 .plot (
482
484
weight ["age" ], weight ["measurement" ], color = color_secondary , label = "weight"
483
485
)
484
486
485
- if show_excluded_values == True :
487
+ if show_excluded_values is True :
486
488
ax1 .scatter (
487
489
excluded_height .age , excluded_height .measurement , c = "black" , marker = "x"
488
490
)
489
491
ax2 .scatter (
490
492
excluded_weight .age , excluded_weight .measurement , c = "black" , marker = "x"
491
493
)
492
494
493
- if show_trajectory_with_exclusions == True :
495
+ if show_trajectory_with_exclusions is True :
494
496
ax1 .plot (
495
497
included_height ["age" ],
496
498
included_height ["measurement" ],
@@ -509,7 +511,7 @@ def overlap_view_double_pediatrics(
509
511
510
512
fig .tight_layout () # otherwise the right y-label is slightly clipped
511
513
512
- if include_carry_forward == True :
514
+ if include_carry_forward is True :
513
515
carry_forward_height = height [height .clean_value == "Exclude-Carried-Forward" ]
514
516
carry_forward_weight = weight [weight .clean_value == "Exclude-Carried-Forward" ]
515
517
ax1 .scatter (
@@ -594,7 +596,7 @@ def five_by_five_view(obs_df, subjids, param, wt_df, ht_df, bmi_df, linestyle):
594
596
for x in range (nrows ):
595
597
try :
596
598
subjid = subjids [x * 5 + y ]
597
- except IndexError as ie :
599
+ except IndexError :
598
600
# No more subjects to render
599
601
break
600
602
individual = obs_df [obs_df .subjid == subjid ]
@@ -758,15 +760,15 @@ def top_ten(
758
760
in the notebook.
759
761
"""
760
762
working_set = merged_df
761
- if age != None :
763
+ if age is not None :
762
764
working_set = working_set .loc [
763
765
working_set .rounded_age .ge (age [0 ]) & working_set .rounded_age .le (age [1 ])
764
766
]
765
- if sex != None :
767
+ if sex is not None :
766
768
working_set = working_set [working_set .sex == sex ]
767
- if wexclusion != None :
769
+ if wexclusion is not None :
768
770
working_set = working_set [working_set .weight_cat .isin (wexclusion )]
769
- if hexclusion != None :
771
+ if hexclusion is not None :
770
772
working_set = working_set [working_set .height_cat .isin (hexclusion )]
771
773
# if order == 'largest':
772
774
# working_set = working_set.nlargest(10, field)
@@ -796,7 +798,7 @@ def top_ten(
796
798
"BMIz" ,
797
799
]
798
800
]
799
- if out == None :
801
+ if out is None :
800
802
return working_set
801
803
else :
802
804
out .clear_output ()
0 commit comments