Skip to content

Commit cd6f53d

Browse files
committed
Refactor square function. Use math.pow instead of multiplication.
1 parent 40da0f0 commit cd6f53d

File tree

1 file changed

+60
-55
lines changed

1 file changed

+60
-55
lines changed

braininventory/get.py

Lines changed: 60 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,49 @@ def today():
2626
return pd.DataFrame()
2727

2828

29+
def __clean_affiliations(df):
30+
# Need to combine the universities so the pie chart shows a single university's total samples under the same area.
31+
# right now there is one area of the pie chart that says 'Allen Institute for Brain Science' and 'Allen Instititute for Brain Science ' (with a space!)
32+
# we need it to recognize that the Allen Institue for Brain Science has contributed a total number of samples equal to the sum of both those areas in the pie chart
33+
Allen = df[df["affiliation"] == "Allen Institute for Brain Science"]
34+
35+
# ^we set a variable 'Allen' equal to the dataframe limited to the rows where it said 'Allen Institute for Brain Science and asked for the count of those rows
36+
# below, we did the same thing but with rows that had Allen with a space
37+
38+
Allen_with_space = df[df["affiliation"] == "Allen Institute for Brain Science "]
39+
40+
accurate_Allen = len(Allen) + len(Allen_with_space)
41+
42+
del affiliations["Allen Institute for Brain Science "]
43+
44+
# Now we can add the counts we had before. (We deleted Allen with a space, but we still have the number of Allen with a space)
45+
# reassign the Allen Institute for Brain Science variable to the actual total number (4715)
46+
47+
affiliations["Allen Institute for Brain Science"] = len(Allen) + len(
48+
Allen_with_space
49+
)
50+
51+
# Now we need to do the same thing with UCLA
52+
# 1) limit the dictionary to ones that read 'University of California, Los Angeles' and the one that says 'University of California, Los Angeles (UCLA)'
53+
54+
No_UCLA = affiliations["University of California, Los Angeles"]
55+
56+
UCLA_present = affiliations["University of California, Los Angeles (UCLA)"]
57+
58+
# 2) Now we found the counts of both. We have to set the college equal to the sum of the category with no UCLA and the catgory with UCLA and delete the one we don't want.
59+
60+
# del affiliations['University of California, Los Angeles (UCLA)']
61+
# print(len(affiliations))
62+
63+
accurate_Uni = (
64+
affiliations["University of California, Los Angeles"]
65+
+ affiliations["University of California, Los Angeles (UCLA)"]
66+
)
67+
68+
del affiliations["University of California, Los Angeles (UCLA)"]
69+
return affiliations
70+
71+
2972
def __get_number_of_datasets(df):
3073
return len(df)
3174

@@ -54,9 +97,11 @@ def __get_contributor(df):
5497
def __get_affilation(df):
5598
return df["affiliation"].value_counts().to_dict()
5699

100+
57101
def __get_awards(df):
58102
return df["award_number"].unique()
59103

104+
60105
def __get_award_number(df):
61106
return df["award_number"].value_counts().to_dict()
62107

@@ -88,6 +133,7 @@ def __get_technique(df):
88133
def __get_locations(df):
89134
return df["locations"].value_counts().to_dict()
90135

136+
91137
def __get_contributors(df):
92138
"""
93139
This returns an array of contributor names from the contributorname column.
@@ -96,33 +142,36 @@ def __get_contributors(df):
96142

97143

98144
def __get_project_names(df):
99-
'''
145+
"""
100146
Gets the unique list of project names.
101147
102148
Input: dataframe
103149
Output: list
104-
'''
105-
return df['project'].unique()
150+
"""
151+
return df["project"].unique()
152+
106153

107154
def __get_list_of_projects(df):
108-
'''
155+
"""
109156
Get the list of names for unique projects
110157
111158
Input parameter: dataframe
112159
Output: list of projects
113-
'''
114-
115-
return df['project'].unique().to_dict()
160+
"""
161+
162+
return df["project"].unique().to_dict()
163+
116164

117165
def __get_number_of_projects(df):
118-
'''
166+
"""
119167
Get the number of unique projects
120168
121169
Input parameter: dataframe
122170
Output: number of projects
123-
'''
124-
125-
return len(df['project'].unique())
171+
"""
172+
173+
return len(df["project"].unique())
174+
126175

127176
def report():
128177
# Get today's date
@@ -151,47 +200,3 @@ def report():
151200
report["is_reachable"] = df["URL"].apply(__is_reachable)
152201

153202
return report
154-
155-
#Need to combine the universities so the pie chart shows a single university's total samples under the same area.
156-
#right now there is one area of the pie chart that says 'Allen Institute for Brain Science' and 'Allen Instititute for Brain Science ' (with a space!)
157-
#we need it to recognize that the Allen Institue for Brain Science has contributed a total number of samples equal to the sum of both those areas in the pie chart
158-
Allen = df[df['affiliation'] == 'Allen Institute for Brain Science' ]
159-
print(len(Allen))
160-
161-
#^we set a variable 'Allen' equal to the dataframe limited to the rows where it said 'Allen Institute for Brain Science and asked for the count of those rows
162-
#below, we did the same thing but with rows that had Allen with a space
163-
164-
Allen_with_space = df[df['affiliation'] == 'Allen Institute for Brain Science ' ]
165-
print(len(Allen_with_space))
166-
167-
accurate_Allen = len(Allen) + len(Allen_with_space)
168-
print(accurate_Allen)
169-
170-
del affiliations['Allen Institute for Brain Science ']
171-
print(affiliations)
172-
173-
#Now we can add the counts we had before. (We deleted Allen with a space, but we still have the number of Allen with a space)
174-
#reassign the Allen Institute for Brain Science variable to the actual total number (4715)
175-
176-
affiliations['Allen Institute for Brain Science'] = len(Allen) + len(Allen_with_space)
177-
print(affiliations)
178-
179-
#Now we need to do the same thing with UCLA
180-
# 1) limit the dictionary to ones that read 'University of California, Los Angeles' and the one that says 'University of California, Los Angeles (UCLA)'
181-
182-
No_UCLA = affiliations['University of California, Los Angeles']
183-
print(No_UCLA)
184-
185-
UCLA_present = affiliations['University of California, Los Angeles (UCLA)']
186-
print(UCLA_present)
187-
188-
# 2) Now we found the counts of both. We have to set the college equal to the sum of the category with no UCLA and the catgory with UCLA and delete the one we don't want.
189-
190-
#del affiliations['University of California, Los Angeles (UCLA)']
191-
#print(len(affiliations))
192-
193-
accurate_Uni = affiliations['University of California, Los Angeles'] + affiliations['University of California, Los Angeles (UCLA)']
194-
print(accurate_Uni)
195-
196-
del affiliations['University of California, Los Angeles (UCLA)']
197-
print(affiliations)

0 commit comments

Comments
 (0)