본문 바로가기

개발&프로그래밍104

[python] 파일 입출력 기초 가이드 [Python] 파일 입출력 기초 가이드 파일 입출력은 프로그래밍의 기본이자 필수 요소다.Python에서 파일을 다루는 방법부터 실전에서 자주 사용하는 패턴까지 알아보자. 텍스트 파일 읽기/쓰기기본적인 파일 읽기# 전체 파일 읽기with open('example.txt', 'r', encoding='utf-8') as file: content = file.read() print(content)# 한 줄씩 읽기with open('example.txt', 'r', encoding='utf-8') as file: for line in file: print(line.strip()) # strip()으로 줄바꿈 제거# 모든 줄을 리스트로 읽기with open('example.txt'.. 2024. 11. 20.
[python] 리스트와 딕셔너리 완벽 이해하기 [Python] 리스트와 딕셔너리 완벽 이해하기 Python에서 가장 많이 사용되는 데이터 구조인 리스트와 딕셔너리의 기본부터 실전 활용법까지 알아보자.   리스트 기본 연산리스트 생성과 접근# 리스트 생성numbers = [1, 2, 3, 4, 5]mixed = [1, "hello", 3.14, True]# 인덱싱first = numbers[0] # 첫 번째 요소last = numbers[-1] # 마지막 요소# 슬라이싱subset = numbers[1:4] # [2, 3, 4]reversed_list = numbers[::-1] # [5, 4, 3, 2, 1] 리스트 수정# 요소 추가numbers.append(6) # [1, 2, 3, 4, 5, 6]numbers.i.. 2024. 11. 20.
[Python] Matplotlib으로 데이터 시각화하기 [Python] Matplotlib으로 데이터 시각화하기Matplotlib은 Python에서 가장 널리 사용되는 데이터 시각화 라이브러리다.기본 그래프부터 복잡한 시각화까지 다양한 기능을 제공한다.기본 그래프 작성라인 플롯import matplotlib.pyplot as pltimport numpy as np# 데이터 준비x = np.linspace(0, 10, 100)y = np.sin(x)# 기본 라인 플롯plt.figure(figsize=(10, 6))plt.plot(x, y, label='sin(x)')plt.title('Basic Line Plot')plt.xlabel('X axis')plt.ylabel('Y axis')plt.legend()plt.grid(True)plt.show()다양한 그래.. 2024. 11. 19.
[Python] Pandas DataFrame [Python] Pandas DataFramePandas는 데이터 분석을 위한 Python 필수 라이브러리다.DataFrame을 효과적으로 다루는 방법부터 고급 기능까지 상세히 알아보자.  데이터 전처리기본적인 데이터 로딩과 확인import pandas as pd# CSV 파일 로딩df = pd.read_csv('data.csv')# 데이터 기본 정보 확인print(df.info())print(df.describe())# 중복 행 확인 및 제거duplicates = df.duplicated()df_clean = df.drop_duplicates()컬럼 처리# 컬럼 이름 변경df = df.rename(columns={ 'old_name': 'new_name', 'price': 'item_pric.. 2024. 11. 19.