Ranking pand według wartości kolumny [duplikat]
to pytanie ma już odpowiedź tutaj :
grupa pand według roku, ranking według kolumny sprzedaży, w ramce danych z duplikatami danych
(1 ODPOWIEDŹ)
Zamknięty 5 lat temu .
Mam ramkę danych, która ma identyfikatory aukcji i ceny licytacji. Dane są sortowane według ID aukcji (rosnąco) i ceny oferty (malejąco):
Auction_ID Bid_Price
123 9
123 7
123 6
123 2
124 3
124 2
124 1
125 1
Chciałbym dodać kolumnę o nazwie 'Auction_Rank', która klasyfikuje ID aukcji według cen ofertowych:
Auction_ID Bid_Price Auction_Rank
123 9 1
123 7 2
123 6 3
123 2 4
124 3 1
124 2 2
124 1 3
125 1 1
33
Author: Christopher Jenkins, 2015-05-24
1 answers
Oto jeden sposób, aby to zrobić w Pandy-sposób
You could groupby
na Auction_ID
i wziąć rank()
on Bid_Price
with ascending=False
In [68]: df['Auction_Rank'] = df.groupby('Auction_ID')['Bid_Price'].rank(ascending=False)
In [69]: df
Out[69]:
Auction_ID Bid_Price Auction_Rank
0 123 9 1
1 123 7 2
2 123 6 3
3 123 2 4
4 124 3 1
5 124 2 2
6 124 1 3
7 125 1 1
53
Author: Zero,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2019-05-21 12:11:33
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2019-05-21 12:11:33