1
- import requests
2
- import pandas as pd
3
1
import json
4
2
from datetime import date
5
- import pandas as pd
3
+
4
+ import humanize
6
5
import matplotlib .pyplot as plt
6
+ import pandas as pd
7
+ import requests
8
+ import seaborn as sb
9
+ import squarify
7
10
from pandarallel import pandarallel
8
11
9
12
pandarallel .initialize (nb_workers = 8 , progress_bar = True )
10
- import squarify
11
13
import matplotlib .pyplot as plt
14
+ import squarify
12
15
13
16
14
17
def get_random_sample (df ):
@@ -30,27 +33,25 @@ def get_random_sample(df):
30
33
31
34
return result .json ()
32
35
33
- import urllib .request
34
- import matplotlib .pyplot as plt
35
- import seaborn as sb
36
- import squarify
37
36
38
37
def __get_lable_dict (name_lst ):
39
38
"""
40
- input: a list of University names
41
- output: a dictionary with the names as keys and abbreviations that include the first letter of each University name
39
+ input: a list of University names
40
+ output: a dictionary with the names as keys and abbreviations that include the first letter of each University name
42
41
"""
43
- return {uni_name : '' .join (word [0 ].upper () for word in uni_name .split ()) for uni_name in name_lst }
42
+ return {
43
+ uni_name : "" .join (word [0 ].upper () for word in uni_name .split ())
44
+ for uni_name in name_lst
45
+ }
44
46
45
47
46
48
def __get_general_modality_treemap (df ):
47
49
"""
48
- input: dataframe
49
- output: tree map that displays the frequencies of "generalmodality" that occur in dataframe
50
+ input: dataframe
51
+ output: tree map that displays the frequencies of "generalmodality" that occur in dataframe
50
52
"""
51
- modality_counts = df ['generalmodality' ].value_counts ().to_dict ()
52
-
53
- plt .figure (figsize = (14 ,10 ))
53
+ modality_counts = df ["generalmodality" ].value_counts ().to_dict ()
54
+ plt .figure (figsize = (14 , 10 ))
54
55
values = list (modality_counts .values ())
55
56
name = list (modality_counts .keys ())
56
57
abbrName = __get_lable_dict (name )
@@ -60,37 +61,50 @@ def __get_general_modality_treemap(df):
60
61
print (num_labels )
61
62
62
63
ax = squarify .plot (sizes = values , color = colors , label = abbrName .values (), alpha = 0.8 )
63
- ax .axis (' off' )
64
+ ax .axis (" off" )
64
65
ax .invert_xaxis ()
65
- ax .set_aspect (' equal' )
66
+ ax .set_aspect (" equal" )
66
67
67
68
legend_patches = [plt .Rectangle ((0 , 0 ), 1 , 1 , fc = color ) for color in colors ]
68
- plt .legend (legend_patches , name , loc = 'upper left' , bbox_to_anchor = (1 , 1 ), fontsize = 'medium' )\
69
-
69
+ plt .legend (
70
+ legend_patches , name , loc = "upper left" , bbox_to_anchor = (1 , 1 ), fontsize = "medium"
71
+ )
70
72
plt .show ()
71
73
72
- import humanize
73
74
74
75
def __get_pretty_size_statistics (df ):
75
- size_stats = __get_size_statistics (df )
76
+ """
77
+ Pretty version of __get_size_statistics
78
+
79
+ Input: dataframe
80
+ Output: list of strings
81
+ """
82
+ size_stats = __get_size_statistics (df )
83
+
84
+ return [
85
+ humanize .naturalsize (size_stats [0 ]),
86
+ humanize .naturalsize (size_stats [1 ]),
87
+ humanize .naturalsize (size_stats [2 ]),
88
+ humanize .naturalsize (size_stats [3 ]),
89
+ ]
90
+
76
91
77
- return [humanize .naturalsize (size_stats [0 ]), humanize .naturalsize (size_stats [1 ]), humanize .naturalsize (size_stats [2 ]), humanize .naturalsize (size_stats [3 ])]
78
-
79
92
def __get_size_statistics (df ):
80
- '''
81
- Helper method that returns size statistics from size column.
93
+ """
94
+ Helper method that returns size statistics from size column.
95
+
96
+ Input: dataframe
97
+ Output: list of numbers
98
+ """
99
+
100
+ min = df ["size" ].min ()
101
+ max = df ["size" ].max ()
102
+ average = df ["size" ].mean ()
103
+ std = df ["size" ].std ()
82
104
83
- Input: dataframe
84
- Output: list of numbers
85
- '''
105
+ return [min , max , average , std ]
86
106
87
- min = df ['size' ].min ()
88
- max = df ['size' ].max ()
89
- average = df ['size' ].mean ()
90
- std = df ['size' ].std ()
91
107
92
- return [min , max , average , std ]
93
-
94
108
def today ():
95
109
"""
96
110
Get today's snapshot of Brain Image Library.
0 commit comments