본문 바로가기

파이썬

(201)
Python Pandas 박스오피스 180516 순위 분석 - Import Moduleimport datetime as dt import requests import json import pandas from pandas import DataFrame from matplotlib import pyplot from print_df import print_df - Parsing Data+---+----------+------------+---------+-----------+----------+--------------------+------------+------+-----------+---------------+------+--------------+------------+-------------+------------+------------+---------+..
JSON - Data Frame Conversion(Pandas 분석) 1. Sample JSON Site : https://api.androidhive.info/contacts/ 2. Import Moduleimport requests import json from pandas import DataFrame from print_df import print_df 3. Sample Codeimport requests import json from pandas import DataFrame from print_df import print_df url = 'https://api.androidhive.info/contacts' response = requests.get(url) if response.status_code != 200: print("[%d Error] %s" % (r..
JSON - Site JSON data analysis(URL JSON 분석) 1. Import Moduleimport requests import json from print_df import print_df 2. Sample Code- Site URL Response 후 내용 가져와서 출력import requests import json from print_df import print_df url = 'https://api.androidhive.info/contacts' response = requests.get(url) if response.status_code != 200: print("[%d Error] %s" % (response.status_code, response.reason)) quit() response.encoding = 'UTF-8' print_df(resp..
JSON - Types of Data Types / Basic Syntax(데이터 형식의 종류 / 기본 문법) 1. 데이터 형식의 종류 text html XML JSON 형식 텍스트 형식 웹 페이지 화면을 구성하는프로그래밍 언어 다목적 마크업 언어 딕셔너리와 동일한 구조 처리결과 문자열 html 문서(계층적 구조) 요소 또는 특성으로 출력 다른 종류의 언어와 데이터 교환물 출력물 Hello Python Hello Python - Hello Python Hello Python!! {"data": {"item": "Hello Python"}} 2. JSON(JavaScript Object Notation)- 속성-값 쌍( attribute–value pairs and array data types (or any other serializable value)) 또는 "키-값 쌍"으로 이루어진 데이터 오브젝트를 전달하기..
JSON - URL HTTP Connection Basics(HTTP 접속 기초) 1. request 모듈 사용import requests2. 객체 생성import requests response = requests.get('URL')3. 객체 설명response.status_code : 결과 코드를 갖고 있는 변수.(200 - 정상 / 404 - Page Not Found / 500 - 서버에러)response.reason : 에러 메시지를 갖는 변수response.encoding : "utf-8" / "enc-kr" 등을 할당하여 text 속성값의 인코딩을 설정response.text requests : 모듈이 URL에 접속하여 가져온 내용 전문 4. Sample URL : https://api.androidhive.info/contacts 5. Sample Codeimport r..
Python Matplotlib - Txt File Load 그래프 1. TXT 파일을 쉼표로 구분하여 Sample Data File 작성1, 22, 33, 44, 55, 66, 77, 88, 99, 1010, 11 2. Sample Code(import CSV)- Import Moduleimport matplotlib.pyplot as plt import csv- Codeimport matplotlib.pyplot as plt import csv x = [] y = [] with open('sample.txt', 'r') as csvfile: plots = csv.reader(csvfile, delimiter=',') for row in plots: x.append(int(row[0])) y.append(int(row[1])) plt.figure() plt.plot(x..
Pandas - 어린이집 시설 현황 분석(Excel +그래프) 1. 공공기관 Data를 사용하여 분석- DB : http://www.index.go.kr/potal/main/EachDtlPageDetail.do?idx_cd=1583 2. import 모듈from print_df import print_df from pandas import ExcelFile from pandas import DataFrame import matplotlib.pyplot as plt import datetime as dt 3. Pandas 분석- 엑셀파일 읽기xls_file = ExcelFile('children.xlsx') - sheet 표시sheet_names = xls_file.sheet_names['데이터', '메타정보'] Process finished with exit cod..
Pandas - 교통 사고 사망 / 사고 / 부상 그래프 분석 1. 공공기관 Data를 사용하여 분석- DB : http://www.index.go.kr/potal/main/EachDtlPageDetail.do?idx_cd=1614 2. 교통 사고 사망 / 사고 / 분석 DB 추출traffic = { '사고' : [231990, 226878, 221711, 223656, 215354, 223552, 232035, 220917], '사망' : [5838, 5505, 5229, 5392, 5092, 4762, 4621, 4292], '부상' : [361875, 352458, 341391, 344565, 328711, 337497, 350400, 331720], '년도' : [2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016] } 3. ..