파이썬 기초 익히기 11
Q126. Column명을 아래와 같이 변경하세요.

df.columns= ['sepal_length','sepal_width', 'petal_length', 'petal_width', 'class']
df.head()
Q127. Column별 NA값이 존재하는지 확인하세요.
df.isnull().sum()
Q127. 'petal_length'의 10번째부터 29번째 행의 값을 NaN으로 변환하세요.
## 파이썬은 마지막꺼는 안 세기 때문에 29를 입력하면 인덱스가 28인 29번째 행을 의미하게 된
df.iloc[9:29,2] = np.nan
df.head(30)
# print(df.petal_length.isnull().sum()) ## null값 20개인지 확인
.
Q128. Nan값을 다시 1로 채워 넣으세요.
df.petal_length.fillna(1,inplace=True)
print(df.petal_length.isnull().sum())
Q129.Class 컬럼을 삭제하세요.
## 재할당이 더 좋음, 나중에 class가 필요할 수 있으까
# df = df[['sepal_length','sepal_width','petal_length', 'petal_width']]
del df['class']
df.head()
Q130.3개의 행에 대해서 모두 Nan값으로 변경하세요
df.iloc[0:3,:] =np.nan
df.head()

Q131.NaN을 가지고 있는 행을 삭제하시오
df = df.dropna(how ='any') ## how='any' 컬럼 중 하나라도 nan을 가지고 있으면 그 행 삭제
df.head()

Q132.index를 다시 0부터 시작할 수 있도록 수정하세요.
df = df.reset_index(inplace =True)
df.head()

'제로베이스 > Python' 카테고리의 다른 글
| Python 10. Visualization (0) | 2024.07.01 |
|---|---|
| Python 9. Series & DataFrame (0) | 2024.07.01 |
| Python 8. Statistics (0) | 2024.06.29 |
| Python 7. Merge, Concat (0) | 2024.06.29 |
| Python 6. Pivot (0) | 2024.06.29 |