강의

멘토링

커뮤니티

Inflearn Community Q&A

leepyun2506's profile image
leepyun2506

asked

Getting started with Python data analysis using public data

[10/20] Understanding the 5 figures of boxplot and visualizing the selling price

연도를 정수형태로 변경

Written on

·

412

1

연도에 2015.0 을 2015로 변경하려면 어떻게 해야할까요? 

pythonpandasnumpy

Answer 1

0

todaycode님의 프로필 이미지
todaycode
Instructor

안녕하세요.

lineplot은 기본적으로 x축의 값이 연속된 숫자를 가정합니다. 

그래서 버전에 따라 연도에 소숫점이 붙기도 하고 안 붙기도 하는데 최근 버전에서는 소숫점이 생깁니다.

소숫점이 생기는 이유는 각 구간의 값을 추정해서 그리다 보면 2018.5 같은 소숫점이 붙는 구간이 생기게 됩니다.

하지만 소숫점 없이 정수로 보고 싶다면 다음의 방법을 사용해 볼 수 있습니다.

matplotlib 의 ticker 를 사용해서 x축의 값을 integer 로 표시하게 하는 방법입니다.

아래의 코드를 참고해 보세요!

from matplotlib.ticker import MaxNLocator

ax = plt.figure().gca()

df_last.groupby(["연도"])["평당분양가격"].mean().plot()

ax.xaxis.set_major_locator(MaxNLocator(integer=True))

leepyun2506's profile image
leepyun2506

asked

Ask a question