2
2
3
3
def calc_average_citations (in_df , max_year = None , sort = False ):
4
4
"""Calculate the average citations since year of publication.
5
-
6
- If no `max_year` is specified, calculate using the latest
7
- year in given dataset.
5
+
6
+ If no `max_year` is specified, calculate using the latest
7
+ year in given dataset.
8
8
9
9
Example
10
10
==========
@@ -18,7 +18,7 @@ def calc_average_citations(in_df, max_year=None, sort=False):
18
18
Parameters
19
19
==========
20
20
* in_df : Pandas DataFrame
21
- * max_year: int or None, year to calculate average citations from.
21
+ * max_year: int or None, year to calculate average citations from.
22
22
23
23
Returns
24
24
==========
@@ -27,15 +27,15 @@ def calc_average_citations(in_df, max_year=None, sort=False):
27
27
assert hasattr (in_df , 'citations' ), \
28
28
'DataFrame has to have `citation` column. Use `get_num_citations()` first'
29
29
out_df = in_df .copy ()
30
-
31
- max_year_in_data = out_df .year .max ()
32
-
33
- if max_year not None :
34
- max_year = int (max_year )
35
- assert max_year_in_data <= max_year , \
36
- "Given max_year must be later than any year found in dataset."
30
+
31
+ max_year_in_data = out_df .year .max ()
32
+
33
+ if max_year not None :
34
+ max_year = int (max_year )
35
+ assert max_year_in_data <= max_year , \
36
+ "Given max_year must be later than any year found in dataset."
37
37
else :
38
- max_year = out_df .year .max ()
38
+ max_year = out_df .year .max ()
39
39
out_df .loc [:, 'Avg. Citations' ] = (out_df .citations / ((max_year - out_df .year ) + 1 )).astype (float ).round (2 )
40
40
41
41
if sort :
0 commit comments