1-4. 시각화
2020. 7. 16. 11:59ㆍ데이터 분석/파이썬
1-3. 해시태그 정리하기
https://hyebit.tistory.com/50 1-2. 중복데이터 제거 및 파일 합치기 https://hyebit.tistory.com/49 1-1. 인스타그램 크롤링하기 위의 그림 처럼 해시태그 관광을 찾으면 주소가 아래와 같이 나옵니다. https://..
hyebit.tistory.com
우선 시각화에 필요한 패키지를 불러오고
import matplotlib.pyplot as plt
import seaborn as sns
from matplotlib import font_manager, rc
import sys
막대그래프에 사용될 글꼴을 설정해 줍니다.
if sys.platform in ['win32', 'win64']:
font_name = 'malgun gothic'
elif sys.platform == 'darwin':
font_name = 'AppleGothic'
rc('font', family = font_name)
tag와 counts만 선택하여 상위 50개의 데이터를 선정하여
tag_counts_df = pd.DataFrame(tag_counts_selected.most_common(50))
tag_counts_df.columns = ['tags', 'counts']
막대그래프를 그려줍니다.
plt.figure(figsize =(15,11))
sns.barplot(x = 'counts', y = 'tags', data = tag_counts_df)
plt.savefig('C:/Users/Desktop/gbtriptag-barplot.png')
그다음으로 워드 클라우드에 필요한 패키지를 불러오고
import matplotlib.pyplot as plt
from wordcloud import WordCloud
import platform
윈도의 경우와 맥의 경우로 나누어 글꼴 설정을 해주고
if platform.system() == 'Windows':
font_path = "c:/Windows/Fonts/malgun.ttf"
elif platform.system() == "Darwin":
font_path = "/Users/$USER/Library/Fonts/AppleGothic.ttf"
워드 클라우드를 그려줍니다.
wordcloud=WordCloud(font_path= font_path,
background_color="white",
max_words=100,
relative_scaling= 0.3,
width = 800,
height = 400
).generate_from_frequencies(tag_counts_selected)
plt.figure(figsize=(15,10))
plt.imshow(wordcloud)
plt.axis('off')
plt.savefig('C:/Users/Desktop/gbtriptag-wordcloud.png')
< 위 글은 "직장인을 위한 데이터 분석 실무"를 참고하였습니다 >
'데이터 분석 > 파이썬' 카테고리의 다른 글
1-3. 해시태그 정리하기 (1) | 2020.07.16 |
---|---|
1-2. 중복데이터 제거 및 파일 합치기 (0) | 2020.07.16 |
1-1. 인스타그램 크롤링하기 (0) | 2020.07.16 |
1.경상북도 관광 해시태그 분석 (0) | 2020.07.16 |