Skip to content

Commit 944d3d6

Browse files
authored
Wrapped code into helper function
1 parent 8fc6982 commit 944d3d6

File tree

1 file changed

+8
-12
lines changed

1 file changed

+8
-12
lines changed

braininventory/get.py

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,14 @@
77
import matplotlib.pyplot as plt
88

99

10-
url = 'https://download.brainimagelibrary.org/inventory/daily/reports/today.json'
11-
file_path, _ = urllib.request.urlretrieve(url)
12-
df = pd.read_json(file_path)
13-
items = df.affiliation.unique()
14-
frequency = {}
15-
16-
for item in items:
17-
if item in frequency:
18-
frequency[item] += 1
19-
else:
20-
frequency[item] = 1
21-
print(frequency)
10+
def __get_affiliation_frequency(df):
11+
'''
12+
Get affiliation frequency.
13+
14+
Input: dataframe
15+
Output: a frequency dictionary
16+
'''
17+
return df['affiliation'].value_counts().to_dict()
2218

2319
def today():
2420
"""

0 commit comments

Comments
 (0)