
* 겪고 있는 문제 상황을 최대한 자세하게 작성해주세요.
* 문제 해결을 위해 어떤 시도를 해보았는지 구체적으로 함께 알려주세요.
average 변수에는 연령대별 완강률 평균이 들어가있으니
시각화 단계에서 'average.index'를 입력하면 x축에 10대부터 50대까지 표시될꺼라고 예상했는데 5단위로 표시되더라구요. 아마 그것때문에 'plt.xticks([10,20,30,40,50])' 가 들어가 있는것 같은데 'average.index' 입력했을때 왜 x축에 5단위로 숫자가 입력돼서 나타나는건가요??
작성한 코드 및 에러 메세지
#라이브러리 불러오기
import pandas as pd
import matplotlib.pyplot as plt
# 한글깨짐 방지
plt.rc('font', family='NanumBarunGothic')
sparta_data = pd.read_table('파일경로',sep=',')
#하위 5개의 데이터 확인하기
sparta_data.tail()
#나이대별 수강율 평균 구하기
progress_rate_by_age = sparta_data.groupby('age')['progress_rate'].sum()
progress_rate_by_age
number_people_by_age = sparta_data.groupby('age')['_id'].count()
number_people_by_age
average = progress_rate_by_age/number_people_by_age
#plt.figure(width, height) : 넓이와 높이 만큼 이미지를 생성한다는 것을 말해줍니다!
plt.figure(figsize=(6,6))
#그래프의 x축 눈금 설정
plt.xticks([10,20,30,40,50])
#plt.bar(X축값, Y축값)
plt.bar(average.index, average,width=8)
#그래프의 바에 각 수치율을 추가하기
bar = plt.bar(average.index, average,width=8)
for rect in bar:
height = rect.get_height()
plt.text(rect.get_x() + rect.get_width()/2.0, height, '%.1f' % height, ha='center', va='bottom', size = 12)
#그래프의 제목
plt.title('[나이대별 평균 수강율]',fontsize=15,pad=20)
#그래프의 x축 라벨 이름
plt.xlabel('나이',fontsize=12,labelpad=20)
#그래프의 y축 라벨 이름
plt.ylabel('수강생(명)',fontsize=14,rotation=360,labelpad=35)
#그래프를 화면에 나타나도록 합니다.
plt.show()
