Python 데이터 분석
-
Python 데이터분석 기초 17 - Matplotlib(차트 호출)Python 데이터 분석 2022. 11. 2. 11:43
Matplotlib http://matplotlib.org 플로팅 라이브러리로 matplotlib.pyplot 모듈을 사용하여 그래프 등의 시각화 가능. 그래프 종류 : line, scatter, contour(등고선), surface, bar, histogram, box, ... Figure 모든 그림은 Figure라 부르는 matplotlib.figure.Figure 클래스 객체에 포함. 내부 plot이 아닌 경우에는 Figure는 하나의 아이디 숫자와 window를 갖는다. figure()를 명시적으로 적으면 여러 개의 윈도우를 동시에 띄우게 된다. # Matplotlib # - http://matplotlib.org # - 플로팅 라이브러리로 matplotlib.pyplot 모듈을 사용하여 그래프..
-
Python 데이터분석 기초 16 - web 에서 JSON 문서 읽기, DataFrame으로 만든 자료를 html 로 변형Python 데이터 분석 2022. 11. 1. 17:51
# web 에서 JSON 문서 읽기 import json import urllib.request as req url = "https://raw.githubusercontent.com/pykwon/python/master/seoullibtime5.json" plainText = req.urlopen(url).read().decode() print(type(plainText)) # jsonData = json.loads(plainText) # str --> dict : json 디코딩 print(type(jsonData)) # print(jsonData['SeoulLibraryTime']['row'][0]['LBRRY_NAME']) # row 0번째의 LBRRY_NAME 호출 libDatas = jsonDa..
-
Python 데이터분석 기초 15 - df 자료로 슬라이싱(iloc, loc), 문자열을 int 타입으로 형변환Python 데이터 분석 2022. 11. 1. 17:36
print('----df 자료로 슬라이싱...----') print('iloc')# iloc print(df.iloc[0]) # 1차원 배열 취급 print(df.iloc[0:2, :]) # 0행부터 2행 전까지 모든 열, 2차원 배열 취급 print(df.iloc[0:2, 0:1]) # 0행부터 2행 전까지 0열 print(df.iloc[0:2, 0:2]) # 0행부터 2행 전까지 1열까지 print() print(df['지역'][0:2]) # 지역 칼럼의 0행과 1행 print() print(df['지역'][:2]) # 지역 칼럼의 0행과 1행 print() print('loc') # loc print(df.loc[1:3]) # 1행부터 3행 print(df[1:4]) # 1행부터 3행 print(d..
-
Python 데이터분석 기초 14 - 기상청 제공 날씨정보 XML 자료 읽기Python 데이터 분석 2022. 11. 1. 16:57
# 기상청 제공 날씨정보 XML 자료 읽기 import urllib.request from bs4 import BeautifulSoup import pandas as pd url = "http://www.weather.go.kr/weather/forecast/mid-term-rss3.jsp" data = urllib.request.urlopen(url).read() soup = BeautifulSoup(data, 'html.parser') # print(soup) print('find method 사용') # find method print() title = soup.find('title').string print(title) wf = soup.find('wf').string print(wf) city ..
-
Python 데이터분석 기초 13 - BeautifulSoup으로 XML 문서 처리Python 데이터 분석 2022. 11. 1. 16:32
# BeautifulSoup으로 XML 문서 처리 import urllib.request as req from bs4 import BeautifulSoup url = "https://raw.githubusercontent.com/pykwon/python/master/seoullibtime5.xml" plainText = req.urlopen(url).read().decode() # print(plainText) soup = BeautifulSoup(plainText, 'lxml') # html.parser libData = soup.select('row') for data in libData: name = data.find('lbrry_name').text # 대문자로 안 나오면 소문자로 해 보기 add..
-
네이버웹툰 html 웹 가져오기 예제Python 데이터 분석 2022. 11. 1. 16:29
import urllib.request as req from bs4 import BeautifulSoup import requests url = "https://comic.naver.com/index" webtoon = req.urlopen(url) soup = BeautifulSoup(webtoon, 'html.parser') # print(soup) datas =soup.select('ol > li > a') # print(soup.select('ol > li > a')) for a in datas: if(a.string != None): print("{}".format(a.string).strip()) 김부장-53화 그게 뭔지 아세요? 내가 키운 S급들-54화 : 대화(1) 여신강림-외전-8화[수아..
-
Python 데이터분석 기초 12 - 네이버 제공 코스피 정보를 읽어 csv 파일로 저장Python 데이터 분석 2022. 11. 1. 16:27
# 네이버 제공 코스피 정보를 읽어 csv 파일로 저장 import csv import requests from bs4 import BeautifulSoup url = "https://finance.naver.com/sise/sise_market_sum.naver?&page={}" fname = "네이버_코스피.csv" # fObj = open(fname, mode = 'w', encoding = 'UTF-8', newline = '') # 공백 행 제외 fObj = open(fname, mode = 'w', encoding = 'UTF-8-sig', newline = '') # 엑셀에서 읽을 때 한글 깨짐 writer = csv.writer(fObj) title = "N 종목명 현재가 전일비 등락률 액..
-
Python 데이터분석 기초 11 - 일정 시간 마다 웹 문서 읽기Python 데이터 분석 2022. 11. 1. 13:08
# 일정 시간 마다 웹 문서 읽기 # import schedule # pip install schedule 스케쥴러 모듈 지원 import time import datetime import urllib.request as req from bs4 import BeautifulSoup import requests def work(): url = "https://finance.naver.com/marketindex/" # data = req.urlopen(url) # 방법 1, 데이터를 보낼 때 인코딩하여 바이너리 형태로 보낸다. data = requests.get(url).text # 방법 2, 데이터를 보낼 때 딕셔너리 형태로 보낸다. soup = BeautifulSoup(data, 'html.parser..