[Pandas] 판다스의 구조 - Series, DataFrame 생성하기

Jaeyoung·2022년 10월 18일
0

Pandas 란?

pandas is a fast, powerful, flexible and easy to use open source data analysis and manipulation tool, built on top of the Python programming language.

  • 엑셀과 같이 행, 열로 된 구조를 다루는 데이터 분석 도구
  • DataFrameSeries 이해 필요

How to load Pandas

import pandas as pd

Series

1차원 자료구조
1차원 리스트와 유사하지만 Series는 index에 이름을 부여할 수 있음

DataFrame

2차원 자료구조
행 (row) 과 열(column) 으로 이루어 짐

시리즈 (Series)

Series is a one-dimensional labeled array capable of holding any data type (integers, strings, floating point numbers, Python objects, etc.).
The axis labels are collectively referred to as the index

  • list 와 다른 점 : 시리즈는 index를 사용할 수 있음
  • How to create a Series
s = pd.Series(data, index=index, name="name")
  • data
- python dictionary
- an ndarray
- a scalar Value 
  • index
- 인덱스를 지정하지 않으면, 0을 시작으로 정수로 자동으로 생성 됨
- 반면에, data에 딕셔너리를 넣으면 key 값이 index로 들어감 => 따로 지정해주지 않아도 됨
  • Name
name = "" 로 시리즈에 이름을 부여할 수 있음
=> DataFrame 에선, column 하나를 셀렉하여 이름을 부여할 수 있음 

데이터프레임 (DataFrame)

DataFrame is a 2-dimensional labeled data structure with columns of potentially different types.

  • How to create a DataFrame
d = pd.DataFrame(data, index=index, columns=columns, dtype=dtype)
  • data
- Dict of 1D ndarrays, lists, dicts, or Sereis
- 2D numpy.ndarray
- Structured or record ndarray
- A Series
- Another DataFrame
  • index
- 인덱스 지정하지 않으면, 0을 시작으로 정수로 자동으로 생성 됨
- 인덱스를 지정하려면, index = [] 로 설정하면 됨
  • columns
- data에 딕셔너리 형태를 넣으면, key 값이 컬럼명이 됨
- columns = [] 에 넣어줘도 됨
  • dtype
- 데이터 타입을 지정할 수 있음
- dtype = float (정수를 넣어도 실수형태로 데이터 만들어 짐)

참고문헌

profile
데이터 분린이:)

0개의 댓글