我的数据框已被重新使用,因此索引值失去了顺序。
在下面的示例中,当我选择df_ranking.Ticker =='WRB'时,我希望得到0而不是478。
In [113]: df_ranking.head()
Out[113]:
Ticker TrendScoreStr TrendScoreNum
478 WRB GCAGA 2000100000200
259 ISRG CMAMA 2000100000000
18 ALGN DGAGA 2000001000200
106 CINF GADMA 2000001000100
450 TRV GADMA 2000001000100
答案 0 :(得分:1)
执行此操作:
In [1788]: df_ranking.reset_index(drop=True, inplace=True)
In [1789]: df_ranking
Out[1789]:
Ticker TrendScoreStr TrendScoreNum
0 WRB GCAGA 2000100000200
1 ISRG CMAMA 2000100000000
2 ALGN DGAGA 2000001000200
3 CINF GADMA 2000001000100
4 TRV GADMA 2000001000100
In [1790]: df_ranking[df_ranking.Ticker.eq('WRB')]
Out[1790]:
Ticker TrendScoreStr TrendScoreNum
0 WRB GCAGA 2000100000200