본문 바로가기

python

(197)
Python - 한국기상청 도시별 현재 날씨 Data 분석 시각화 1. Import Moduleimport pandas as pd from print_df import print_df import matplotlib.pyplot as plt 2. Sample Data : https://developer-ankiwoong.tistory.com/259 3. Codeimport pandas as pd from print_df import print_df import matplotlib.pyplot as plt df = pd.read_csv('weather.csv', encoding='utf=8') df_list = list(df['지역']) index_dict = {} for i, v in enumerate(df_list): index_dict[i] = v df.drop('..
Python - 한국기상청 도시별 현재 날씨 정보 분석 후 csv 저장 1. import moduleimport requests from bs4 import BeautifulSoup as BS 2. Sample URL : http://www.weather.go.kr/weather/observation/currentweather.jsp 3. HTML Parsing Codeimport requests from bs4 import BeautifulSoup as BS url = 'http://www.weather.go.kr/weather/observation/currentweather.jsp' response = requests.get(url) if response.status_code != 200: print("%d 에러가 발생했습니다." % response.status_code..
Python - Import 1. Import모듈 / 패키지 라이브러리를 가져오는 명령어 2. import module 기본 방법import 모듈 import 모듈1, 모듈2 모듈.변수 모듈.함수() 모듈.클래스() 3. import as : 긴 모듈 이름 대신 별명으로 로드하는법import 모듈 as 별명 4. from import : 모듈안에 필요한 변수만 가져오는 법from 모듈 import 변수 from 모듈 import 함수 from 모듈 import 클래스 from 모듈 import 변수, 함수, 클래스 from 모듈 import * 5. from import as : 3 + 4 형식from 모듈 import 변수 as 별명 from 모듈 import 함수 as 별명 from 모듈 import 클래스 as 별명 from ..
Python Matplotlib -Subplots(한 화면에 여러개 그래프) 1. import moduleimport random import matplotlib.pyplot as plt from matplotlib import style 2. Sample Codeimport random import matplotlib.pyplot as plt from matplotlib import style style.use('fivethirtyeight') fig = plt.figure() def create_plots(): xs = [] ys = [] for i in range(10): x = i y = random.randrange(10) xs.append(x) ys.append(y) return xs, ys ax1 = fig.add_subplot(2, 2, 1) ax2 = fig.ad..
Hannanum 한글 형태소 분석 후 워드클라우드 생성 - 대한민국헌법 1. import modulefrom konlpy.tag import Hannanum from wordcloud import WordCloud import matplotlib.pyplot as plt from collections import Counter 2. 대한민국 헌법 3. 한글 형태소 분석 Code- TXT 파일 로드text = '' with open("data/대한민국헌법.txt", encoding="utf-8") as f: text = f.read() - 한나눔 사용 변수 지정hannanum = Hannanum() - 명사 분석nouns = hannanum.nouns(text) print(nouns) - 문장 분석morphs = hannanum.morphs(text) print(morphs)..
kkma 한글 형태소 분석 후 워드클라우드 생성 - 대한민국헌법 1. import modulefrom konlpy.tag import Kkma from wordcloud import WordCloud import matplotlib.pyplot as plt from collections import Counter 2. 대한민국 헌법 3. 한글 형태소 분석 Code- TXT 파일 로드text = '' with open("data/대한민국헌법.txt", encoding="utf-8") as f: text = f.read() - 꼬꼬마 사용 변수 지정kkma = Kkma() - 문장 분석sentences = kkma.sentences(text) print(sentences) - 명사 분석nouns = kkma.nouns(text) print(nouns) - 형태소 분석po..
Pandas - Scientists Data 분석 1. Sample Data 2. Import Moduleimport pandas as pd from print_df import print_df 3. Data 분석- CSV(comma separated values) : Data들이 comma(,)로 구분된 파일. - CSV File Load(CSV는 ,로 구분 되어있으므로 sep를 안줘도 무방)df = pd.read_csv('data\scientists.csv') - Data의 행(row) / 열(column) 갯수 확인df = pd.read_csv('data\scientists.csv') print('shape:', df.shape)shape: (8, 5) Process finished with exit code 0 - Data의 양이 적으므로 CSV..
Pandas - Gapminder Data 분석(그래프 분석) 3 1 Sample Data 2. import moduleimport pandas as pd import matplotlib.pyplot as plt 3. 그래프 분석import pandas as pd import matplotlib.pyplot as plt df = pd.read_csv('data\gapminder.tsv', sep='\t') year_lifeExp_mean = df.groupby('year')['lifeExp'].mean() year = df.loc[0: , 'year'] year_drop = year.drop_duplicates() year_x = [] for i in year_drop: year_x.append(i) plt.rcParams["font.family"] = 'NanumGo..