Pandas
Created : October 02, 2019
Pandas: Python์์ ๋ฐ์ดํฐ์ฒ๋ฆฌ๋ฅผ ์ํด ์กด์ฌํ๋ ๊ฐ์ฅ ์ธ๊ธฐ์๋ ๋ผ์ด๋ธ๋ฌ๋ฆฌ. 2์ฐจ์ ๋ฐ์ดํฐ๋ฅผ ํจ์จ์ ์ผ๋ก ๊ฐ๊ณต,์ฒ๋ฆฌํจ.
Pandas์ ํต์ฌ ๊ฐ์ฒด = DataFrame
- ์ฌ๋ฌ ๊ฐ์ ํ๊ณผ ์ด๋ก ์ด๋ค์ง 2์ฐจ์ ๋ฐ์ดํฐ๋ฅผ ๋ด๋ ๋ฐ์ดํฐ ๊ตฌ์กฐ์ฒด
- Index : ๊ฐ๋ณ ๋ฐ์ดํฐ๋ฅผ ๊ณ ์ ํ๊ฒ ์๋ณํ๋ key๊ฐ. Series, DataFrame์ ๋ชจ๋ Index๋ฅผ key๊ฐ์ผ๋ก ๊ฐ์ง.
- Series : ์ด์ด ํ๋๋ฟ์ธ ๋ฐ์ดํฐ ๊ตฌ์กฐ์ฒด
- DataFrame : ์ด์ด ์ฌ๋ฌ๊ฐ์ธ ๋ฐ์ดํฐ ๊ตฌ์กฐ์ฒด. DataFrame์ ์ฌ๋ฌ๊ฐ์ Series๋ก ์ด๋ค์ง.
import pandas as pd
1. DataFrame
read_csv( )
ํ์ผ ๋ก๋ฉํ๊ธฐ
- csv : ์ด์
์ฝค๋ง(,)
๋ก ๊ตฌ๋ถ - ์ฝค๋ง ์ธ์ ๋ค๋ฅธ ๋ฌธ์๋ก ๊ตฌ๋ถํ๋ ค๋ฉด : read_csv(โํ์ผ๋ช
โ,
sep=โ\tโ
) read_table( )
: ์ด์ ํญ์ผ๋ก ๊ตฌ๋ถ
df = pd.read_csv('C:/Users/.../train.csv')
- csv ํ์ผ์ ๋ก๋ฉํด DataFrame ๊ฐ์ฒด๋ก ๋ฐํ
- ๋ณ๋ค๋ฅธ ์ง์ ์์ผ๋ฉด, csv ํ์ผ ์ฒซ๋ฒ์งธ ์ค์ ๋ฌธ์์ด์ ์นผ๋ผ๋ช ์ผ๋ก.
-
๋งจ ์ผ์ชฝ์ 0,1,2,3,โฆ ์ซ์๋ค์ด Pandas์ Index ๊ฐ
- ๋ชจ๋ DataFrame ๋ด์ ๋ฐ์ดํฐ๋ ์์ฑ๋๋ ์๊ฐ ๊ณ ์ ์ Index๊ฐ์ ๊ฐ์ง
< Explore DataFrame >
df.head(N)
df์ ๋งจ ์์ ์๋ N๊ฐ์ ํ ํ์ํ๊ธฐ (๊ธฐ๋ณธ๊ฐ 5๊ฐ)
df.shape
df ํฌ๊ธฐ ์์๋ณด๊ธฐ. ํ๊ณผ ์ด์ tuple ํํ๋ก ๋ฐํ.
df.info( )
์ด ๋ฐ์ดํฐ ๊ฑด์, ๋ฐ์ดํฐ ํ์
, Null ๊ฑด์ ๋ฑ
df.describe( )
- ์ซ์ํ ๋ฐ์ดํฐ๊ฐ์ ๋ถํฌ๋, ํ๊ท ๊ฐ, ์ต๋๊ฐ, ์ต์๊ฐ ๋ฑ
- ์ค์ง ์ซ์ํ ์ด๋ง ์กฐ์ฌ. object ํ์
์ ์ด์ ์๋์ผ๋ก ์ถ๋ ฅ์์ ์ ์ธ์ํด
df[โcolumnโ].value_counts( )
- ์นผ๋ผ ๋ฐ์ดํฐ๊ฐ์ ์ ํ๊ณผ ๊ฑด์ ํ์ธํ๊ธฐ
- df[ ] ์์ ์ด๋ช ์ ๋ ฅํ๋ฉด Series ํํ๋ก ํน์ ์ด์ ๋ฐ์ดํฐ์ ์ด ๋ฐํ๋จ
- value_counts๋ DataFrame ์ ์ฒด์๋ ์ ์ฉ ์๋๊ณ Series์๋ง ์ ์ฉ๋จ. (๊ทธ๋์ df['์ด'] ์ด๋ ๊ฒ ํด๋น ์ด์ ์ง์ ํด์ค์ผํจ)
< ndarray, ๋ฆฌ์คํธ โ DataFrame๋ก ๋ณํํ๊ธฐ >
DataFrame์ column๋ช ์ ๊ฐ์ง๊ณ ์์ด์, DataFrame์ผ๋ก ๋ณํ์ ์ด column๋ช ์ ์ง์ ํด์ค์ผํจ.
- ๋ฏธ์ง์ ์ ์๋์ผ๋ก column๋ช ์ ํ ๋น
colname = ['col1']
# ๋ฆฌ์คํธ๋ฅผ ์ด์ฉํด DataFrame ์์ฑ (columns์ธ์๋ก column๋ช
์ง์ )
df_list = pd.DataFrame([1, 2, 3], columns=colname)
# NumPy ndarray๋ฅผ ์ด์ฉํด DataFrame ์์ฑ
df_array = pd.DataFrame(np.array([1, 2, 3]), columns=colname)
colname = ['col1', 'col2', 'col3']
df_list = pd.DataFrame([[1, 2, 3], [11, 12, 13]], columns=colname)
df_array = pd.DataFrame(np.array([[1, 2, 3], [11, 12, 13]]), columns=colname)
< ๋์ ๋๋ฆฌ โ DataFrame๋ก ๋ณํํ๊ธฐ >
- key๊ฐ์ column๋ช ์ผ๋ก, value๊ฐ์ ํด๋น column์ ๋ฐ์ดํฐ๋ก ๋ณํ
- key๋ ๋ฌธ์์ด๋ก, value๋ ๋ฆฌ์คํธ๋ ndarray ํํ๋ก ๋์ ๋๋ฆฌ๋ฅผ ๊ตฌ์ฑ
dict = {'col1':[1, 11], 'col2':[2, 22], 'col3':[3, 33]}
df_dict = pd.DataFrame(dict)
< DataFrame โ ndarray, ๋ฆฌ์คํธ, ๋์ ๋๋ฆฌ๋ก ๋ณํํ๊ธฐ >
df.values
DataFrame โ ndarray
arr = df.values
>>> arr
[[ 1, 2, 3],
[11, 22, 33]] # NumPy์ ndarray ํ์
์ผ๋ก ๋ณํ๋จ
df.values.tolist( )
DataFrame โ ๋ฆฌ์คํธ
df.values
๋ก ์ป์ ndarray์tolist( )
ํธ์ถ
lis = df.values.tolist()
>>> lis
[[1, 2, 3], [11, 22, 33]]
df.to_dict(โlistโ)
DataFrame โ ๋์ ๋๋ฆฌ
- ์ธ์๋ก โlistโ ์ ๋ ฅํ๋ฉด ๋์ ๋๋ฆฌ์ value๊ฐ์ด ๋ฆฌ์คํธํ์ผ๋ก ๋ฐํ
- ์ธ์๋ก ์๋ฌด๊ฒ๋ ์ ๋ ฅ์ํ๋ฉด value๊ฐ์ด ๋์ ๋๋ฆฌ
dict = df.to_dict('list')
>>> dict
{'col1':[1, 11], 'col2':[2, 22], 'col3':[3, 33]}
dict = df.to_dict()
>>> dict
{'col1': {0: 1, 1: 11}, 'col2': {0: 2, 1: 22}, 'col3': {0: 3, 1: 33}}
2. DataFrame ์์ฑ, ์์ , ์ญ์
< ์๋ก์ด column ์ถ๊ฐํ๊ธฐ >
- ์๋ก์ด series๊ฐ ๊ธฐ์กด DataFrame์ ์ถ๊ฐ๋จ
- Series์ ์์๊ฐ์ ํ ๋นํ๋ฉด ๋ชจ๋ ๋ฐ์ดํฐ๊ฐ์ด ์ผ๊ด์ ์ผ๋ก ์ ์ฉ๋จ
- ๊ธฐ์กด column์ ๋ฐ์ดํฐ๋ฅผ ์ด์ฉํด ์๋ก์ด series๋ฅผ ๋ง๋ค์๋ ์์
df['new'] = 0
df['age'] = 2019 - df['born']
df['age_by_10'] = df['age'] * 10
< ๊ธฐ์กด์ column ๋ฐ์ดํฐ๊ฐ ์ผ๊ด ์์ ํ๊ธฐ >
df['age_by_10'] = df['age_by_10'] + 100
< DataFrame ๋ฐ์ดํฐ ์ญ์ ํ๊ธฐ >
df.drop(labels=None, axis=0, inplace=False)
# 'name, age, address' column์ด ์ญ์ ๋ df๋ฅผ ๋ฐํ
drop_df = df.drop(['name', 'age', 'address'], axis=1)
- labels : ์ญ์ ์ํ๋ ํ์ ์ธ๋ฑ์ค๊ฐ or column๋ช ์ ๋ ฅ
- axis :
axis=0
ํ ์ญ์ ,axis=1
์ด ์ญ์ -
inplace
- ๊ธฐ๋ณธ๊ฐ False โ ์๋ DataFrame์ ๊ทธ๋๋ก ์ ์ง & drop๋ DataFrame์ ์๋ก์ด ๊ฐ์ฒด๋ณ์๋ก ๋ฐํ
inplace=True
โ ์๋ DataFrame์ ๋ฐ์ดํฐ๋ฅผ ์ญ์ & drop๋ ๊ฒฐ๊ณผ๋ฅผ ์๋กญ๊ฒ ์ ์ฉ. ๋ฐํ๋๋ ๊ฐ์None
3. Index ๊ฐ์ฒด
df.index
Index ๊ฐ์ฒด๊ฐ ํ์ธํ๊ธฐ
df.index.values
Index ๊ฐ์ฒด์ ndarray ๊ฐ ํ์ธํ๊ธฐ
df.reset_index( )
์๋กญ๊ฒ ์ธ๋ฑ์ค๋ฅผ ์ฐ์ ์ซ์ํ์ผ๋ก ํ ๋น. ๊ธฐ์กด ์ธ๋ฑ์ค๋ โindexโ๋ผ๋ ์๋ก์ด column๋ช ์ผ๋ก ์ถ๊ฐ.
- Parameter๊ฐ์ผ๋ก drop=True ์ค์ ํ๋ฉด ๊ธฐ์กด ์ธ๋ฑ์ค๊ฐ ์๋ก์ด ์นผ๋ผ์ผ๋ก ์ถ๊ฐ๋์ง ์๊ณ ์ญ์ ๋จ
4. Data Selection & Filtering
< [ ] ์ฐ์ฐ์ >
-
DataFrame ๋ค์ [ ]์ ์นผ๋ผ์ ์ง์ ํด ์นผ๋ผ ์ง์ ์ฐ์ฐ์ ์ฌ์ฉ
- ex)
df[โageโ]
- ex)
-
Index ํํ๋ก ๋ณํ๊ฐ๋ฅํ ํํ์ (์ฌ๋ผ์ด์ฑ or Boolean ์ธ๋ฑ์ฑ) ์ [ ]๋ด์ ์ ๋ ฅ ๊ฐ๋ฅ
- df[0:2] : ์ฒซ 2๊ฐ ๋ฐ์ดํฐ ํ์ ์ถ์ถ โ ๊ฐ๋ฅ์ ํ์ง๋ง ์ด๋ ๊ฒ ์ฌ๋ผ์ด์ฑํด์ ๋ฐ์ดํฐ ์ถ์ถํ๋ ๋ฐฉ์์ ๋น์ถ!
- df[df[โageโ] == 30] : age์ด ๊ฐ์ด 30์ธ ๋ฐ์ดํฐ๋ง ์ถ์ถ
DataFrame[ ]์๋ ์นผ๋ผ ์ง์ or Boolean ์ธ๋ฑ์ฑ์ผ๋ก๋ง ์ฌ์ฉํ ๊ฒ !!!
< ix[ ] ์ฐ์ฐ์ >
ix[ํ, ์ด] like ix[0, 'age']
โ 0๋ฒ์งธ ํ + 'age'์ด์ ํด๋นํ๋ ๋ฐ์ดํฐ๊ฐ ์ถ์ถ
- ํ : ํ์ index๊ฐ (index๊ฐ ์ซ์ํ์ผ ๊ฒฝ์ฐ ๋ช ์นญ ๊ธฐ๋ฐ)
- ์ด : ์นผ๋ผ๋ช or ์นผ๋ผ index๊ฐ
์นผ๋ผ๋ช ๊ณผ ์นผ๋ผ์ index๊ฐ ๋๊ฐ๊ฐ ํผ์ฉ๋์ด ix ์ฐ์ฐ์๋ ๊ณง ์ฌ๋ผ์ง๊ณ , loc[ ]๊ณผ iloc[ ]์ผ๋ก ๋๋์ด์ง. ํผ๋์ ์ค์ด๊ธฐ ์ํด loc[ ], iloc[ ] ์ค ํ๋๋ง ์ฌ์ฉํ๋ ๊ฒ์ด ์ข์. (๋ด์๊ฐ: ๋๋๋ก์ด๋ฉด loc[ ]์ผ๋ก ํต์ผํ๋๊ฒ ๊น๋ํด๋ณด์)
< iloc[ ] ์ฐ์ฐ์ >
์นผ๋ผ ์์น(position) ๊ธฐ๋ฐ ์ธ๋ฑ์ฑ
- ํ,์ด์ ์์น ์ขํ๋ก ๋ฐ์ดํฐ์ ์ ๊ทผ
- ํ,์ด ๊ฐ์ผ๋ก int or ์ฌ๋ผ์ด์ฑ or ํฌ์๋ฆฌ์คํธ๋ฅผ ์ ๋ ฅ
df.iloc[0, 0] # 1๋ฒ์งธ ํ, 1๋ฒ์งธ ์ด ๊ฐ
df.iloc[0, 'Name'] # ์ค๋ฅ๋ฐ์
df.iloc[0:2, 0] # 1,2๋ฒ์งธ ํ, 1๋ฒ์งธ ์ด ๊ฐ (0:2๋ 0,1๋ง ํฌํจ)
< loc[ ] ์ฐ์ฐ์ >
์นผ๋ผ ๋ช ์นญ(label) ๊ธฐ๋ฐ ์ธ๋ฑ์ฑ
- DataFrame์ index๋ ์นผ๋ผ๋ช ์ผ๋ก ๋ฐ์ดํฐ์ ์ ๊ทผ
- ํ์๋ index๊ฐ์, ์ด์๋ ์นผ๋ผ๋ช ์ ์ ๋ ฅ
df.loc['one', 'Name'] # index๊ฐ์ด 'one'์ธ ํ์ 'Name'์ด ๊ฐ
df.loc[1, 'Name'] # index๊ฐ ์ซ์ํ์ธ ๊ฒฝ์ฐ
df.loc[1:2, 'Name'] # 1,2๋ฒ์งธ ํ์ 'Name'์ด ๊ฐ (1:2๋ 1,2 ๋ชจ๋ ํฌํจ)
loc[ ]์์ ์ฌ๋ผ์ด์ฑ์ '์์๊ฐ๋ถํฐ ์ข ๋ฃ๊ฐ-1' ๊น์ง๊ฐ ์๋๋ผ '์์๊ฐ๋ถํฐ ์ข ๋ฃ๊ฐ'๊น์ง์! ๋ช ์นญ์ ๊ธฐ๋ฐ์ผ๋ก ์ธ๋ฑ์ฑ์ ํ๋๋ฐ ๋ช ์นญ์ ์ซ์ํ์ด ์๋ ์๋ ์์ด์ -1์ ํ ์ ์๊ธฐ ๋๋ฌธ.
< Boolean Indexing >
- ์ํ๋ ๋ฐ์ดํฐ์ ์กฐ๊ฑด์ ix[ ] ๋ด์ ์ ๋ ฅํ๋ฉด ์๋์ผ๋ก ์ํ๋ ๊ฐ์ ํํฐ๋ง
-
[ ], ix[ ], loc[ ]์์ ๊ณตํต์ผ๋ก ์ง์
- iloc[ ]๋ ์ ์ํ๋ง ์ง์ํ๊ธฐ ๋๋ฌธ์ Boolean ์ธ๋ฑ์ฑ X
- and ์กฐ๊ฑด :
&
, or ์กฐ๊ฑด :|
, Not ์กฐ๊ฑด :~
df[df['Age'] >= 30] # 30์ธ ์ด์์ธ ์ฌ๋์ ๋ชจ๋ ๋ฐํ
df[df['Age'] >= 30][['Name', 'Age']] # 30์ธ ์ด์์ธ ์ฌ๋์ '์ด๋ฆ, ๋์ด'๋ง ์ถ์ถ
df.loc[df['Age'] >= 30, ['Name', 'Age']] # loc ์ด์ฉ
df[(df['Age'] >= 30) & (df['Sex'] == 'female')] # 30์ธ ์ด์์ธ ์ฌ์๋ง
5. Sorting
sort_values(by, ascending, inplace)
DataFrame๊ณผ Series์ ์ ๋ ฌ
by='์นผ๋ผ๋ช '
: ํด๋น ์นผ๋ผ์ผ๋ก ์ ๋ ฌascending=True
(๊ธฐ๋ณธ๊ฐ) : ์ค๋ฆ์ฐจ์,ascending=False
: ๋ด๋ฆผ์ฐจ์inplace=False
(๊ธฐ๋ณธ๊ฐ) : ์๋ณธ ๋ฐ์ดํฐ๋ ๊ทธ๋๋ก ์ ์ง, ์ ๋ ฌ๋ DataFrame์ ๋ฐํ
6. Aggregation ํจ์
min( )
, max( )
, sum( )
, count( )
, mean( )
๋ฑ๋ฑ
-
DataFrame์์ aggregation ํธ์ถํ ๊ฒฝ์ฐ ๋ชจ๋ ์นผ๋ผ์ ํด๋น ํจ์๋ฅผ ์ ์ฉ
- ex)
df.count( )
ํ๋ฉด ๋ชจ๋ ์ด ๊ฐ๊ฐ์ count๋ฅผ ๋ฐํ
- ex)
- ํน์ ์นผ๋ผ์ ํจ์ ์ ์ฉํ๋ ค๋ฉด
df[['A์ด', 'B์ด']].max( )
์ฒ๋ผ ๋์ ์นผ๋ผ๋ค๋ง ์ถ์ถ
7. groupby( )
by='์นผ๋ผ๋ช '
: ํด๋น ์นผ๋ผ์ผ๋ก groupby
df.groupby('Sex').count() # ๋จ๋
๊ตฌ๋ถํด 'Sex' ์นผ๋ผ ์ ์ธํ ๋๋จธ์ง ๋ชจ๋ ์นผ๋ผ์ count์ ์ฉ
df.groupby('Sex')[['Name', 'Age']].count() # ๋จ๋
๊ตฌ๋ถํด Name, Age ์นผ๋ผ์๋ง count์ ์ฉ
Sex | Name | Age |
---|---|---|
male | 257 | 257 |
female | 261 | 261 |
df.groupby('Sex')['Age'].agg([max, min]) # ๋จ๋
๊ตฌ๋ถํด ๋์ด์ max, min๊ฐ ๋ฐํ
Sex | max | min |
---|---|---|
male | 70 | 15 |
female | 75 | 14 |
agg_format = {'Age':'max', 'Amount':'sum', 'Salary':'mean'}
df.groupby('Sex').agg(agg_format) # ์ฌ๋ฌ๊ฐ์ ์นผ๋ผ์ ์๋ก ๋ค๋ฅธ aggํจ์๋ฅผ ์ธ ๊ฒฝ์ฐ
Sex | Age | Amount | Salary |
---|---|---|---|
male | 70 | 482 | 5271.23 |
female | 75 | 469 | 5086.01 |
8. ๊ฒฐ์ ๋ฐ์ดํฐ ์ฒ๋ฆฌํ๊ธฐ
- ์นผ๋ผ์ ๊ฐ์ด ์๋ Null์ธ ๊ฒฝ์ฐ. NumPy์ NaN์ผ๋ก ํ์
- ML ์๊ณ ๋ฆฌ์ฆ์ ์ด NaN ๊ฐ์ ์ฒ๋ฆฌํ์ง ์์ผ๋ฏ๋ก NaN๊ฐ์ ๋ค๋ฅธ ๊ฐ์ผ๋ก ๋์ฒดํด์ผํจ
isna( ) or isnull()
NaN ์ฌ๋ถ ํ์ธ
df.isna() # NaN์ด๋ฉด True, ์๋๋ฉด False
Sex | Name | Age | Amount | Salary | |
---|---|---|---|---|---|
0 | False | False | True | True | False |
1 | False | False | True | False | True |
2 | False | False | False | False | False |
>>> df.isna().sum() # NaN ๊ฐ์ ๊ตฌํ๊ธฐ
Sex 0
Name 0
Age 2
Amount 1
Salary 1
# Null๊ฐ ๊ฐ์ ๊ตฌํ ๋ df.isnull().sum()
fillna( )
NaN ๊ฐ์ ๋ค๋ฅธ ๊ฐ์ผ๋ก ๋์ฒด
# 1๋ฒ์งธ ๋ฐฉ๋ฒ
df['Age'] = df['Age'].fillna(df['Age'].mean()) # 'Age'์นผ๋ผ์ NaN๊ฐ์ ํ๊ท ๊ฐ์ผ๋ก ๋์ฒด
# 2๋ฒ์งธ ๋ฐฉ๋ฒ
df['Age'].fillna(df['Age'].mean(), inplace=True)
fillna( )ํ ๊ฒฐ๊ณผ๊ฐ์ ์๋ณธ ๋ฐ์ดํฐ์ ์์ ํ๋ ค๋ฉด
- ์ฒซ๋ฒ์งธ ๋ฐฉ๋ฒ์ฒ๋ผ ๋ฐํ๊ฐ์ df['Age']์ ๋ค์ ์ ํด์ฃผ๊ฑฐ๋,
- ๋๋ฒ์งธ ๋ฐฉ๋ฒ์ฒ๋ผ
inplace=True
๋ฅผ ์ถ๊ฐํด์ผ ์๋ณธ ๋ฐ์ดํฐ๊ฐ ์์ ๋จ
9. apply lambda๋ก ๋ฐ์ดํฐ ๊ฐ๊ณตํ๊ธฐ
Python์ lambda์์ Pandas DataFrame์ ์ ์ฉํ ๊ฒ
df['Name_len'] = df['Name'].apply(lambda x: len(x))
df[['Name', 'Name_len']].head(3)
Name | Name_len | |
---|---|---|
0 | Brad Pitt | 9 |
1 | Angelina Jolie | 14 |
2 | Matt Damon | 10 |
# 20์ธ ์ด์์ 'Adult', 20์ธ ๋ฏธ๋ง์ 'Child'๋ก ๊ตฌ๋ถํ๊ธฐ
df['Ageclass'] = df['Age'].apply(lambda x: 'Adult' if x >= 20 else 'Child')
df[['Age', 'Ageclass']].head(5)
Age | Ageclass | |
---|---|---|
0 | 42 | Adult |
1 | 17 | Child |
2 | 6 | Child |
3 | 29 | Adult |
4 | 61 | Adult |
# 61์ธ ์ด์์ 'Elderly', 20~60์ธ๋ 'Adult', 20์ธ ๋ฏธ๋ง์ 'Child'๋ก ๊ตฌ๋ถํ๊ธฐ
df['Ageclass'] = df['Age'].apply(lambda x: 'Elderly' if x > 60
else ('Adult' if x >= 20 else 'Child')
df[['Age', 'Ageclass']].head(5)
else if๋ ์ง์ํ์ง ์์ผ๋ฏ๋ก else์ ์ ( )๋ก ๋ดํฌํด ( ) ๋ด์์ ๋ค์ if else ์ ์ฉํด์ผํจ.
- ํ์ง๋ง else if๊ฐ ํ์ํ ๊ฒฝ์ฐ๋ else์ ์ด ๋ง์ด ํ์ํ ๊ฒฝ์ฐ์๋ ๋ฐ๋ก ๋ณ๋์ ํจ์๋ฅผ ๋ง๋๋๊ฒ ๋์.
-
Ageclass๋ฅผ ๋ฆฌํดํ๋
def get_ageclass(age)
ํจ์๋ฅผ ๋ง๋ค์ด์df['Age'].apply(lambda x: get_ageclass(x))
๋ก ์ฒ๋ฆฌ
Age | Ageclass | |
---|---|---|
0 | 78 | Elderly |
1 | 14 | Child |
2 | 66 | Elderly |
3 | 30 | Adult |
4 | 45 | Adult |