본문 바로가기

데이터 분석4

python 파일 용량이 큰 파일을 읽을 경우 from functools import partial def chunked_file(fp, block_size=1024 * 1024 * 50): # 50MB return [chunk for chunk in iter(partial(fp.read, block_size), '')] def read_file(file_path): with open(file_path) as f_read: return chunked_file(f_read) # 사용방법 file_path = "/data/large_file.txt" for content in read_file(file_path): someting(content) 2022. 9. 1.
pandas, pyplot로 데이터를 시각화해보자 1. Hello, Seaborn 패키지 로드 register_matplotlib_converters : matplotlib에 pandas 포맷터 및 변환기를 등록한다. %matplotlib inline : IPython 에서 제공하는 Rich output 대한 표현방식으로 도표와 같은 그림, 소리, 애니메이션들을 출력 (Rich output) 하는 것이다. import pandas as pd pd.plotting.register_matplotlib_converters() import matplotlib.pyplot as plt %matplotlib inline import seaborn as sns print(">>> 로드 완료") 데이터 로드 피파 랭킹 데이터를 로드해보자 인덱스 컬럼을 데이터열로 설정.. 2022. 3. 9.
Pandas 구분자로 되어 있는 행 여러 줄 행으로 만들기 1. 데이터 로드 영화 데이터를 로드해본다. 데이터를 보면 "장르 (genres)" 컬럼의 값들이 | 구분자들로 나누어져 있는 것을 알 수 있다. 이 구분자를 쪼개서 다시 여러개의 행 데이터로 재구성을 하고자한다. movies = pd.read_csv("movies.csv") movies.head(10) movieId title genres 0 1 Toy Story (1995) Adventure|Animation|Children|Comedy|Fantasy 1 2 Jumanji (1995) Adventure|Children|Fantasy 2 3 Grumpier Old Men (1995) Comedy|Romance 3 4 Waiting to Exhale (1995) Comedy|Drama|Romance 4 .. 2022. 3. 3.
Pandas 를 활용해보자 Pandas 기초 사용법 1. 생성, 쓰기, 읽기 import pandas as pd 데이터 생성 pd.DataFrame({'컬럼1': [33, 40], '컬럼2': [42, 21]}) 컬럼1 컬럼2 0 33 42 1 40 21 pd.DataFrame({'철수': ['남자', 183], '영희': ['여자', 162]}) 철수 영희 0 남자 여자 1 183 162 pd.DataFrame({'철수': ['남자', 183], '영희': ['여자', 162]}, index=['성별', '키']) 철수 영희 성별 남자 여자 키 183 162 시리즈 pd.Series([1, 2, 3, 4, 5]) 0 1 1 2 2 3 3 4 4 5 dtype: int64 pd.Series([30, 35, 40], index=['.. 2022. 3. 2.
728x90
반응형