Pandas 기초 -2
Summary Functions and Maps
1. Summary functions
reviews.points.describe()
out:
count 129971.000000
mean 88.447138
...
75% 91.000000
max 100.000000
Name: points, Length: 8, dtype: float64
-> numerical data
reviews.taster_name.describe()
out:
count 103727
unique 19
top Roger Voss
freq 25514
Name: taster_name, dtype: object
reviews.taster_name.value_counts()
out:
Roger Voss 25514
Michael Schachner 15134
...
Fiona Adams 27
Christina Pickard 6
Name: taster_name, Length: 19, dtype: int64
각 이름이 몇 번 나왔는지 세어준다.
2. Maps
map()
review_points_mean = reviews.points.mean()
reviews.points.map(lambda p: p - review_points_mean)
이렇게 하면 편차를 구할 수 있다.
map()에 전달하는 함수는 Series의 형태로 반환이 된다.
apply()
만든 함수를 적용할 수 있게 해준다.
def remean_points(row):
row.points = row.points - review_points_mean
return row
reviews.apply(remean_points, axis='columns')
remean_points라는 함수를 만들었을 때, reviews에 적용할 수 있도록 해준다.
추가
reviews.country + " - " + reviews.region_1
out: 0 Italy - Etna 1 NaN ... 129969 France - Alsace 129970 France - Alsace Length: 129971, dtype: object
이런 식으로 변형도 가능하다.
Grouping and Sorting
1. Groupwise analysis
reviews.groupby('points').points.count()
out:
points
80 397
81 692
...
99 33
100 19
groupby()
주어진 와인에 동일한 포인트 값을 할당하는 리뷰 그룹을 생성함
각 그룹에 대해 points()열을 잡고 몇 번 나타나는지 계산을 한다.
groupby함수의 이해
reviews.groupby('winery').apply(lambda df: df.title.iloc[0])
out:
winery
1+1=3 1+1=3 NV Rosé Sparkling (Cava)
10 Knots 10 Knots 2010 Viognier (Paso Robles)
...
àMaurice àMaurice 2013 Fred Estate Syrah (Walla Walla V...
Štoka Štoka 2009 Izbrani Teran (Kras)
Length: 16757, dtype: object
reviews.groupby(['country']).price.agg([len, min, max])
len | min | max | |
---|---|---|---|
country | |||
Argentina | 3800.0 | 4.0 | 230.0 |
Armenia | 2.0 | 14.0 | 15.0 |
... | ... | ... | ... |
Ukraine | 14.0 | 6.0 | 13.0 |
Uruguay | 109.0 | 10.0 | 130.0 |
agg()
동시에 다른 함수들을 표현할 수 있도록 해주는 함수이다.
Author And Source
이 문제에 관하여(Pandas 기초 -2), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://velog.io/@isg/Pandas-기초-2저자 귀속: 원작자 정보가 원작자 URL에 포함되어 있으며 저작권은 원작자 소유입니다.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)