문제
Find the Olympics with the highest number of athletes. The Olympics game is a combination of the year and the season, and is found in the 'games' column. Output the Olympics along with the corresponding number of athletes.
선수 수가 가장 많은 올림픽 찾기. 해당 선수 수와 함께 games를 출력
코드
# Import your libraries
import pandas as pd
# Start writing code
olympics_athletes_events.head()
olympics_athletes_events[['games','id']].drop_duplicates().groupby("games")["id"].count().reset_index().sort_values(by="id", ascending=False).head(1)
SQL에서 distinct는 pandas에서는 nunique()라는 집계함수를 사용할 수 있음
cnt = olympics_athletes_events.groupby("games")["id"].nunique()
cnt = cnt.count().reset_index().sort_values(by="id", ascending=False).head(1)
출처
반응형
'Algorithm > Python' 카테고리의 다른 글
[stratascratch] Customer Details(Python) (0) | 2021.08.15 |
---|---|
[stratascratch] Order Details(Python) (0) | 2021.08.15 |
[stratascratch] find the top 10 ranked songs in 2010(Python) (0) | 2021.08.15 |
[stratascratch] number of bathrooms and bedrooms(Python) (0) | 2021.08.15 |
[stratascratch] Count the number of movies that Abigail Breslin nominated for oscar(Python) (0) | 2021.08.07 |