BKS*_*BKS 4 python dataframe pandas
我知道这个问题可能看起来微不足道,但我在任何地方都找不到解决方案。我有一个非常大的 pandas 数据框df,看起来像这样:
conference IF2013 AR2013
0 HOTMOBILE 16.333333 31.50
1 FOGA 13.772727 60.00
2 IEA/AIE 10.433735 28.20
3 IEEE Real-Time and Embedded Technology and App... 10.250000 29.00
4 Symposium on Computational Geometry 9.880342 35.00
5 WISA 9.693878 43.60
6 ICMT 8.750000 22.00
7 Haskell 8.703704 39.00
Run Code Online (Sandbox Code Playgroud)
我想在末尾添加一个额外的列,将其排序为 1,2,3,4 等。所以它看起来像这样:
conference IF2013 AR2013 Ranking
0 HOTMOBILE 16.333333 31.50 1
1 FOGA 13.772727 60.00 2
2 IEA/AIE 10.433735 28.20 3
3 IEEE Real-Time and Embedded Technology and App... 10.250000 29.00 4
Run Code Online (Sandbox Code Playgroud)
我似乎不知道如何添加一个填充的额外列,该列只放置一系列连续的数字。
你可以试试:
df['rank'] = df.index + 1
print df
# conference IF2013 AR2013 rank
#0 HOTMOBILE 16.333333 31.5 1
#1 FOGA 13.772727 60.0 2
#2 IEA/AIE 10.433735 28.2 3
#3 IEEE Real-Time and Embedded Technology and App... 10.250000 29.0 4
#4 Symposium on Computational Geometry 9.880342 35.0 5
#5 WISA 9.693878 43.6 6
#6 ICMT 8.750000 22.0 7
#7 Haskell 8.703704 39.0 8
Run Code Online (Sandbox Code Playgroud)
rank或者与参数一起使用ascending=False:
df['rank'] = df['conference'].rank(ascending=False)
print df
# conference IF2013 AR2013 rank
#0 HOTMOBILE 16.333333 31.5 1
#1 FOGA 13.772727 60.0 2
#2 IEA/AIE 10.433735 28.2 3
#3 IEEE Real-Time and Embedded Technology and App... 10.250000 29.0 4
#4 Symposium on Computational Geometry 9.880342 35.0 5
#5 WISA 9.693878 43.6 6
#6 ICMT 8.750000 22.0 7
#7 Haskell 8.703704 39.0 8
Run Code Online (Sandbox Code Playgroud)