์ปฌ๋ผ(column)์ ์ธ๋ฑ์ค(index)๋ก ๋ง๋ค๊ธฐ
df.set_index('name', inplace = True)
bike | pants | shirts | suits | |
name | ||||
A | 20 | 30 | 15.0 | 45.0 |
B | 15 | 5 | 2.0 | 7.0 |
C | 20 | 30 | NaN | NaN |
< - > ๋ค์ index๋ฅผ ์ปฌ๋ผ์ผ๋ก ๋ง๋ค๊ธฐ
df.reset_index(inplace = True)
name | bike | pants | shirts | suits | |
0 | A | 20 | 30 | 15.0 | 45.0 |
1 | B | 15 | 5 | 2.0 | 7.0 |
2 | C | 20 | 30 | NaN | NaN |
์๋ก์ด ์ปฌ๋ผ(column) ๋ง๋ค๊ธฐ
# ์๋ก์ด ์ปฌ๋ผ name์ ๋ง๋ค๋, ๋ฐ์ดํฐ๋ A,B,C๋ผ๊ณ ๋ฃ์.
hat | pants | shirts | suits | |
0 | 20 | 30 | 15.0 | 45.0 |
1 | 15 | 5 | 2.0 | 7.0 |
2 | 20 | 30 | NaN | NaN |
df['name'] = ['A' , 'B' , 'C']
df
bike | pants | shirts | suits | name | |
0 | 20 | 30 | 15.0 | 45.0 | A |
1 | 15 | 5 | 2.0 | 7.0 | B |
2 | 20 | 30 | NaN | NaN | C |
์ปฌ๋ผ(column)๋ช ๋ฐ๊พธ๊ธฐ
name | bike | pants | shirts | suits | |
store 1 | A | 20 | 30 | 15.0 | 45.0 |
store 2 | B | 15 | 5 | 2.0 | 7.0 |
store 3 | C | 20 | 30 | NaN | NaN |
df.rename ( columns= { 'bikes' : 'hat' , 'suits' : 'shoes' } ,inplace = True)
name | hat | pants | shirts | shoes | |
store 1 | A | 20 | 30 | 15.0 | 45.0 |
store 2 | B | 15 | 5 | 2.0 | 7.0 |
store 3 | C | 20 | 30 | NaN | NaN |
์ธ๋ฑ์ค(index)๋ช ๋ฐ๊พธ๊ธฐ
name | hat | pants | shirts | shoes | |
store 1 | A | 20 | 30 | 15.0 | 45.0 |
store 2 | B | 15 | 5 | 2.0 | 7.0 |
store 3 | C | 20 | 30 | NaN | NaN |
df.rename( index = {'store 3' : 'last sotre' }, inplace = True )
name | hat | pants | shirts | shoes | |
store 1 | A | 20 | 30 | 15.0 | 45.0 |
store 2 | B | 15 | 5 | 2.0 | 7.0 |
last store | C | 20 | 30 | NaN | NaN |
'Python > Python Language' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
SciPy(Scientific Python) Numpy๋ฅผ ๊ธฐ๋ฐ์ผ๋ก ํ๋ ๊ณผํ ๊ณ์ฐ ๋ผ์ด๋ธ๋ฌ๋ฆฌ (0) | 2024.04.16 |
---|---|
๋ฐ์ดํฐํ๋ ์(DataFrame)์ ๋ฐฐ์ด ์กฐ์ธ(join)๊ณผ ๋ฐฐ์ด๋ถํ (split) (0) | 2024.04.09 |
Pandas์์ ์ ๊ณตํ๋ ๋ฌธ์์ด(Str) ํจ์ (2) | 2024.04.09 |
Pandas(ํ๋ค์ค) 1์ฐจ์ 2์ฐจ์ ์์ฑ๊ณผ ๋ฐ์ดํฐ ์ ๋ฆฌ (0) | 2024.04.05 |
Python(ํ์ด์ฌ) ํจ์ def ์ฌ์ฉํ๊ธฐ (0) | 2024.04.04 |