본문 바로가기

프로그래밍/Python

Python 라이브러리 정리

1. XML 분석 : BeautifulSoup


xml = open(filename, "r", encoding="utf-8").read()
soup = BeautifulSoup(xml, 'html.parser')

info = {}
for location in soup.find_all("location"):
  name = location.find('city').string
  weather = location.find('wf').string
  if not (weather in info):
    info[weather[ = []
  info[weather].append(name)

for weather in info.keys():
  print("+", weather)
  for name in info[weather]:
    print("| - ", name)


2. JSON 분석 : json (기본 라이브러리)

import urllib.request as req
import os.path, random
import json

#JSON 데이터 내려받기
url = 'https://api.github.com/repositories"
savename = "repo.json"
if not os.path.exists(url):
  req.rulretrieve(url, savename)

#JSON 파일 분석하기
items = json.load(open(savename, "r", encoding="utf-8"))
# 또는
# s = open(savename, "r", encoding="utf-8").read()
# items = json.loads(s)

#출력하기
for item in items:
  print(item["name"] + " - " + item["owner]["login])


2. YAML 분석 : yaml (기본 라이브러리)

3. csv/tsv 분석 : cvs, codecs (기본 라이브러리),  Pandas and xlrd(엑셀 수정 가능토록 하는 모듈)

$ pip3 install pandas

$ pip3 install xlrd

4. 엑셀파일 분석 : openpyxl

$ pip3 install openpyxl

or 

C:\Python34\Scripts\pip3.exe install openpyxl