import pandas as pd
// Pandas 호출
1차원 형태의 데이터 구조
인덱스와 값이 1:1로 구성되어있는 형태
population = pd.Series([9904312,3448737,2890451,1466052],
index = ['서울','부산','인천','광주'])
// 서울 9904312
// 부산 3448737
// 인천 2890451
// 광주 1466052
// dtype: int64
population.values
// array([9904312, 3448737, 2890451, 1466052], dtype=int64)
// Series 데이터의 값들은 넘파이 배열 형태이다.
population.index
// Index(['서울', '부산', '인천', '광주'], dtype='object')
population.dtype
// dtype('int64')
population.name = '인구수'
// 서울 9904312
// 부산 3448737
// 인천 2890451
// 광주 1466052
// Name: 인구수, dtype: int64
population.index.name = '도시'
// 도시
// 서울 9904312
// 부산 3448737
// 인천 2890451
// 광주 1466052
// Name: 인구수, dtype: int64
리스트의 인덱싱&슬라이싱과 동일하게 사용한다
population[[0,3,1]]
population[['서울','광주','부산']]
// 도시
// 서울 9904312
// 광주 1466052
// 부산 3448737
// Name: 인구수, dtype: int64
// 다중조건인 경우에는 & 기호를 사용하고 반드시 소괄호()로 우선순위 지정해야 함
population[(population > 2500000) & (population < 5000000)]
// Series명[시작인덱스:끝인덱스(포함x)]
print(population[1:3])
// 인덱스 이름으로 슬라이싱 할 때는 끝값포함
print(population['부산':'인천'])
딕셔너리는 Key와 Value로 구성
Key 값은 index
Value 값은 value
data = {'피카츄':9631,
'파이리':8546,
'꼬부기':1046,
'나옹이':10}
pokemon = pd.Series(data)
pokemon
// 피카츄 9631
// 파이리 8546
// 꼬부기 1046
// 나옹이 10
// dtype: int64
기본적인 연산은 Numpy배열과 동일하게 모두 가능하다.
논리형으로 출력됨
up.notnull()
up[up.isnull()]
// Series명['수정할 인덱스 명'] = 수정할 값
ch['나옹이'] = 60
// Series명['추가할 인덱스 명'] = 추가할 값
ch['또가스'] = 55
del ch['리자몽']
// 없는 값 삭제 시도시 오류 출력