我有以下数据,df:
Year totalPubs ActualCitations
0 1994 71 191.002034
1 1995 77 2763.911781
2 1996 69 2022.374474
3 1997 78 3393.094951我想编写这样的代码:
前两年totalPubs现年/和引文
我希望创建一个名为“影响因子”的新列,并按如下方式生成该列:
for index, row in df.iterrows():
if row[0]>=1996:
df.at[index,'Impact Factor'] = df.at[index, 'ActualCitations'] / (df.at[index-1, 'totalPubs'] + df.at[index-2, 'totalPubs'])发布于 2015-06-22 10:43:32
我相信以下是你想做的事:
In [24]:
df['New_Col'] = df['ActualCitations']/pd.rolling_sum(df['totalPubs'].shift(), window=2)
df
Out[24]:
Year totalPubs ActualCitations New_Col
0 1994 71 191.002034 NaN
1 1995 77 2763.911781 NaN
2 1996 69 2022.374474 13.664692
3 1997 78 3393.094951 23.240376因此,上面使用rolling_sum和shift生成前两年和,然后我们除以该值引文值。
https://stackoverflow.com/questions/30977816
复制相似问题