data분석-파이썬

EunRyeong Park·2022년 9월 24일
0

data

목록 보기
2/2
  • 파일 열기/닫기
file = open(‘data.txt’) 
content = file.read() 
file.close()

# 자동으로 파일 닫기
with open(‘data.txt’) as file: 
 content = file.read()

# 줄단위로 읽기
contents = [] 
with open(‘data.txt’) as file:
 for line in file: 
 contents.append(line)
  • JSON(javascript object notation)
    -웹환경에서 데이터를 주고 받는 가장 표준적인 방식
    -키를 이용하여 원하는 데이터만 빠르게 추출 가능
    -데이터가 쉽게 오염되지 않음
    -다른 포맷에 비해 용량이 큼

  • 집합
    중복이 없고 순서가 없음

union = set1 | set2 # 합집합
intersection = set1 & set2 # 교집합
diff = set1 - set2 # 차집합
xor = set1 ^ set2 # XOR
  • CSV(Comma Separated Value)
    각 열이 특정한 의미를 가짐
    같은 데이터를 저장하는데 용량을 적게 소모함
    데이터 오염에는 취약
import csv 
with open('movies.csv') as file: 
 reader = csv.reader(file, delimiter=',') 
 for row in reader: 
 print(row[0])
  • lambda
def plus(x): 
 return x + x 
plus = lambda x: x + x

0개의 댓글