https://pandas.pydata.org/docs/reference/api/pandas.Series.str.upper.html
pandas.Series.str.upper โ pandas 2.2.1 documentation
Converts first character of each word to uppercase and remaining to lowercase.
pandas.pydata.org
์ด๊ณณ์์ ํ๋ค์ค์ ํจ์์ ๋ณด๋ฅผ ์ ์ ์๋ค.
df.str.replace('a','b') ๋ฐ์ดํฐ์ ๋ฌธ์์ด a๋ฅผ b๋ก ๋ฐ๊ฟ์ค๋ค
- > df.str.replace('$','').astype(float)
#astype(float) ๋ df์ type์ ๋ชจ๋ float๋ก ๋ฐ๊ฟ์ค๋ค. str, int ๋ฑ์ผ๋ก ๋ฐ๊ฟ ์๋ ์๋ค
df.str.upper() ๋ฌธ์์ด ๋ฐ์ดํฐ๋ฅผ ๋ชจ๋ ๋๋ฌธ์๋ก ๋ฐ๊ฟ์ค๋ค
df['Employee Name'].str.upper()
df.str.contains('์ฐพ๊ณ ์ถ์ ๋ฌธ์์ด') ๋ฌธ์์ด์ ํฌํจํ๋ ๋ฐ์ดํฐ๋ฅผ ์ฐพ์์ค๋ค
item_name์ด๋ผ๋ column์ ๋ฐ์ดํฐ๊ฐ
'Chips and Fresh Tomato Salsa', ' Nantucket Nectar' ...์ด๋ผ๊ณ ํ ๋,
'Chips'๋ฅผ ํฌํจํ๋ ๋ฐ์ดํฐ๋ฅผ ์ฐพ๊ณ ์ถ๋ค๋ฉด
df3['item_name'].str.contains('Chips',case=False) #case=False๋ ๋์๋ฌธ์ ๊ตฌ๋ถ์์ด ์ฐพ์์ค๋ค.
๋๋ฌธ์ 'N'์ด ๋ค์ด๊ฐ ๋ฐ์ดํฐ๋ฅผ ์ฐพ๊ณ ์ถ๋ค๋ฉด
df3['item_name'].str.contains('N',na=False) #na=False๋ null๊ฐ์ธ ๋ฐ์ดํฐ๋ฅผ ์ ์ธํ๊ณ ์ฐพ์์ค๋ค
df.str.len() ๋ฌธ์์ด์ ๊ธธ์ด๋ฅผ ๋ฐ์ดํฐํ ํ๋ค
df์ Employee Name์ด๋ผ๋ ์ด์ ๋ฐ์ดํฐ๊ฐ ์๋์ ๊ฐ๋ค๋ฉด
Employee Name
0 CHANEL
1 STEVE
2 MITCH
3 BIRD
df['Employee Name'].str.len()
0 6
1 5
2 5
3 4
Name: Employee Name, dtype: int64
์ด์ธ์๋ ์ฌ์ดํธ๋ฅผ ํ์ฉํ์ฌ ๋ฌธ์์ด ํจ์๋ฅผ ์ฌ์ฉํ ์ ์๋ค.
'Python > Python Language' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
| ๋ฐ์ดํฐํ๋ ์(DataFrame)์ ๋ฐฐ์ด ์กฐ์ธ(join)๊ณผ ๋ฐฐ์ด๋ถํ (split) (0) | 2024.04.09 |
|---|---|
| ๋ฐ์ดํฐํ๋ ์(DataFrame)์ column, index ์ค์ ๋ฐฉ๋ฒ (0) | 2024.04.09 |
| Pandas(ํ๋ค์ค) 1์ฐจ์ 2์ฐจ์ ์์ฑ๊ณผ ๋ฐ์ดํฐ ์ ๋ฆฌ (0) | 2024.04.05 |
| Python(ํ์ด์ฌ) ํจ์ def ์ฌ์ฉํ๊ธฐ (0) | 2024.04.04 |
| ์กฐ๊ฑด๋ฌธ (if, elif, else) ์์ฑํ๊ธฐ (0) | 2024.04.04 |