티스토리 뷰

1. Pandas란?

Pandas는 파이썬에서 데이터 분석을 위해 가장 널리 사용되는 라이브러리 중 하나입니다.

Pandas의 주요 특징

  • 다양한 데이터 형태 지원 (CSV, JSON, Excel 등)
  • 데이터 필터링, 정렬, 그룹화 기능 제공
  • 결측치 처리 및 데이터 정제 가능
  • 데이터 분석을 위한 다양한 통계 함수 제공

Pandas 설치 방법

pip install pandas

2. Pandas의 기본 사용법

2.1 Series

Series는 1차원 데이터 구조로, 인덱스와 값으로 구성됩니다.

import pandas as pd
from pandas import Series

kakao = Series([92600, 92400, 92100, 94300, 92300])
print(kakao)

2.2 DataFrame

DataFrame은 여러 개의 Series가 모인 2차원 데이터 구조입니다.

data = {'col1': [1, 2, 3], 'col2': [4, 5, 6]}
df = pd.DataFrame(data)
print(df)

 

2.3 데이터 조회

print(df.head())  # 처음 5개 행 출력
print(df.tail())  # 마지막 5개 행 출력

2.4 데이터 정렬 및 필터링

df.sort_values(by='col1', ascending=False)
df[df['col2'] > 4]

3. Pandas를 활용한 기상 데이터 분석

Pandas를 이용해 기상 데이터를 분석하고 시각화할 수 있습니다.

3.1 데이터 불러오기

weather = pd.read_csv("weather.csv", encoding='CP949')
print(weather.head())

3.2 날짜 데이터 처리

weather['month'] = pd.DatetimeIndex(weather['일시']).month

3.3 월별 평균 풍속 계산

monthly_wind = weather.groupby('month')['평균 풍속(m/s)'].mean()
print(monthly_wind)

3.4 데이터 시각화

import matplotlib.pyplot as plt

plt.plot(monthly_wind.index, monthly_wind.values, color='red', marker='o')
plt.xlabel('월')
plt.ylabel('평균 풍속(m/s)')
plt.title('월별 평균 풍속 변화')
plt.grid()
plt.show()

 

 

Pandas를 활용하면 복잡한 데이터도 쉽게 분석하고 시각화할 수 있습니다. 다음 포스트에서는 보다 실전적인 데이터를 활용해 분석해보겠습니다!

공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
TAG
more
«   2026/04   »
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
글 보관함