본문 바로가기
개발일지/Pandas

pandas 판다스 틀린부분 복기

by 개발에정착하고싶다 2022. 7. 16.
320x100
# 문제 1
# Check whether the new index contains only unique values (no duplicates)! Is this the case?

cars.index.is_unique

'''
정답을 그냥 cars
라고 변수명만 입력해주었다. unique values에 대해서 보여주라는 가이드를 해석하지 못했기 때문이다.
'''
# 문제 2
# Get the frequency/Counts of all unique values in the index! What is the most frequent value?

# 왜 안나올까? frequency 값이
# cars.describe()

cars.index.value_counts()

'''
이전에는 describe()로 해겨이 되었던 것같은데 잘 안되었고
두번째 시도때 cars.value_counts()를 했으나
역시 결과가 달랐다.
정확하게 cars.index.value_counts()를 해줘야 맞는것이다.
'''
# 문제 3
# Rename the column Labels "horsepower" and "origin" to "hp" and "country"! Fill in the gaps!


# cars.rename(index = {"horsepower":"hp", 'origin':'country'}, inplace=True)
cars.rename(columns= {'horsepower':'hp', 'origin':'country'}, inplace=True)

'''
첫번째 시도때는 # 으로 나열이 되어있는것처럼 index= 하고 index의 값을 변경해주는 명령이였다.
정작 바꾸어야하는 것은 행(컬럼)값인데 말이다.

두번재 시도에서는 columns라고 답안을 보고 따라했고 실행을 정상적으로 했으나, 변형이 되지 않았음을
확인했다.
원인은 horsepower를 horespower라고 오타쳤기 때문이다.
이런걸로 봐서는 오타를 쳐도 딱히 에러가 나지 않는 듯 하다.
그러니 더욱 주의하고 확인하고 또 확인하자
'''
300x250

'개발일지 > Pandas' 카테고리의 다른 글

pandas (판다스) 기초 8 and, or  (0) 2022.07.18
pandas (판다스) 기초 7 filtering  (0) 2022.07.18
pandas 판다스 기초 6  (0) 2022.07.16
pandas 판다스 기초 5  (0) 2022.07.15
pandas 판다스 기초 4  (0) 2022.07.15