Skip to content

Commit 57df14a

Browse files
Allow specification of an anchor point in time (max year)
1 parent a992186 commit 57df14a

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

wosis/analysis/stats.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
__all__ = ['calc_average_citations']
22

3-
def calc_average_citations(in_df, sort=False):
3+
def calc_average_citations(in_df, max_year=None, sort=False):
44
"""Calculate the average citations since year of publication.
55
66
Example
@@ -14,7 +14,8 @@ def calc_average_citations(in_df, sort=False):
1414
1515
Parameters
1616
==========
17-
* df : Pandas DataFrame
17+
* in_df : Pandas DataFrame
18+
* max_year: int or None, year to calculate average citations from.
1819
1920
Returns
2021
==========
@@ -23,7 +24,15 @@ def calc_average_citations(in_df, sort=False):
2324
assert hasattr(in_df, 'citations'), \
2425
'DataFrame has to have `citation` column. Use `get_num_citations()` first'
2526
out_df = in_df.copy()
26-
max_year = out_df.year.max()
27+
28+
max_year_in_data = out_df.year.max()
29+
30+
if max_year not None:
31+
max_year = int(max_year)
32+
assert max_year_in_data <= max_year, \
33+
"Given max_year must be later than any year found in dataset."
34+
else:
35+
max_year = out_df.year.max()
2736
out_df.loc[:, 'Avg. Citations'] = (out_df.citations / ((max_year - out_df.year) + 1)).astype(float).round(2)
2837

2938
if sort:

0 commit comments

Comments
 (0)