일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
- sql연습
- 맷플롯립
- 파이썬수업
- 판다스그래프
- SQL수업
- SQLSCOTT
- 팀플기록
- python수업
- 주피터노트북판다스
- python데이터분석
- sql연습하기
- 주피터노트북맷플롯립
- 파이썬크롤링
- 주피터노트북데이터분석
- Python
- sql따라하기
- 판다스데이터분석
- SQL
- 주피터노트북그래프
- 파이썬데이터분석주피터노트북
- matplotlib
- 파이썬
- 파이썬시각화
- python알고리즘
- 주피터노트북
- 데이터분석시각화
- 파이썬알고리즘
- 파이썬차트
- 수업기록
- 파이썬데이터분석
- Today
- Total
목록파이썬파일읽고쓰기 (4)
IT_developers

json 읽고 쓰기 import json 선언하기 # json 읽기 data = '{"id": "hong", "language": "python", "edition": "3.9", "author": "Guido van Rossum"}' json_data = json.loads(data) # 문자열 형태를 json 로드 print(type(json_data)) # 타입을 딕셔너리로 바꿈 # 딕셔너리라면 key, value 값을 가지고 올수있다 data = '{"id": "hong", "language": "python", "edition": "3.9", "author": "Guido van Rossum"}' json_data = json.loads(data) print( type(json_data), js..

csv 파일 입출력 import csv 선언하기! csv : 클래스 # sample1.csv 읽어오기 with open("data/sample1.csv", "r") as f: # csv 행단위로 읽어옴. reader = csv.reader(f) # reader : 읽어오기 # 헤더명 제거 next(reader) # ['번호', '이름', '가입일시', '나이'] 제거 print(reader) # print(type(reader)) print(dir(reader)) for c in reader: print(c) # sample2 읽어오기 with open("data/sample2.csv", "r") as f: reader = csv.reader(f) for c in reader: print(c) # 옵션 ..

data 폴더 안에 넣기 파일 읽기 with open("data/review.txt", "r", encoding="utf-8") as f: print(f.read()) readline() : 줄 단위로 읽어오기 with open("data/review.txt", "r", encoding="utf-8") as f: print(f.readline()) with open("data/review.txt", "r", encoding="utf-8") as f: line = f.readline() while line: print(line, end=" ") line = f.readline() readlines : 파일의 내용을 리스트로 가져오기 with open("data/review.txt", "r", encodin..

화면 출력 print, 입력 input open("파일명", 모드, encoding...) : 파일을 읽거나 쓸 때 사용 with + open() : close()를 알아서 해줌 f = open("data/test1.txt", "w", encoding="utf-8") f.write("안녕하세요\n반갑습니다.") f.close() with open("data/test1.txt", "w", encoding="utf-8") as f: f.write("안녕하세요\n반갑습니다.") # 1~10까지 파일로 작성 # w : 기존에 있던 내용은 무시하고 새로 작성 f = open("data/test1.txt", "w", encoding="utf-8") for i in range(1, 11): f.write("%d\n"..