# [파이썬] Numpy와 Pandas 구글 검색 지수 추이 비교 - 시각화
# 구글트렌드의 검색지수 데이터를 다운로드한 후 import
gt01 = pd.read_csv(dataPath + 'numpy_pandas_gt_20190808.csv')
gt01.head()
#-------
# 추이를 비교해서 살펴볼 수 있도록 재집계하여 시각화
import matplotlib.style as style
style.use('fivethirtyeight')
# 년-월-일 형식의 날짜 string을 년-월 형식으로 평균으로 집계
gt01['yearmon']= gt01.date.str[:7]
gt01a = gt01.groupby('yearmon').mean().reset_index()
# print(gt01a)
plt.figure(figsize=(15,3))
plt.plot(gt01a['yearmon'], gt01a['pandas'])
plt.plot(gt01a['yearmon'], gt01a['numpy'])
plt.legend(['pandas','numpy'], loc='upper left')
plt.title('Searching Key Libraries for Python Data Analysis [USA. 5Years]')
plt.xticks(rotation=90, size=8)
plt.axhline(gt01a['pandas'].median(), color='silver', linestyle='--')
plt.axhline(gt01a['numpy'].median(), color='silver', linestyle='--')
plt.ylabel('google trend index')
plt.show()
# min max scaling 적용
g1 = gt01a['pandas']
g1 = (g1-g1.min())/(g1.max()-g1.min())
g2 = gt01a['numpy']
g2 = (g2-g2.min())/(g2.max()-g2.min())
# 사용자 정의 함수 형태로 정리
def plotGT(x, g1, g2, titleText):
plt.figure(figsize=(15,3))
plt.plot(x, g1)
plt.plot(x, g2)
plt.legend(['pandas','numpy'], loc='upper left')
plt.title(titleText)
plt.xticks(rotation=90, size=8)
plt.axhline(0.5, color='silver', linestyle='--')
plt.ylabel('google trend index')
plt.show()
# 사용자 정의 함수 실행
plotGT(gt01a['yearmon'], g1, g2, 'Searching Key Libraries for Python Data Analysis [USA. 5Years] - MinMaxScaled')
'Python데이터분석' 카테고리의 다른 글
파이썬: 실전팁 for EDA [전용준.리비젼컨설팅] (0) | 2019.08.27 |
---|---|
[파이썬] 히트맵 heatmap 을 활용한 탐색적 분석 예제 (0) | 2019.08.21 |
[Python 분석]온라인 서점 고객세분화 Visual Data Exploration 예제 (0) | 2019.07.18 |
[Dataset] Supermarket sales from Kaggle (0) | 2019.07.08 |
[슬픈 이야기] why i had to start to move from R to Python (0) | 2019.01.19 |