2주차(4) : Pandas 다루기 - Series
import pandas as pd
s = pd.Series([9904312, 3448737, 2890451, 2466052], index=["서울", "부산", "인천", "대구"])
print(s)
s2 = pd.Series([9904312, 3448737, 2890451, 2466052])
print(s2)
print(s.index)
print(s.values)
print(s.name)
print(s.index.name)
print(s)
s.name = "인구"
s.index.name ="도시"
print(s)
s = s / 1000
print(s)
t = s * 1000
t.name = "인구2"
t.index.name = "도시2"
print(t)
print(s[1], s["부산"])
print(s[3], s["대구"])
print(s[[0, 1, 3]])
print(s[["서울", "부산", "대구"]])
print(s[[True, True, False, True]])
print(s[s > 5000])
print(s[1:3])
print(s["서울":"인천"])
print(s.서울)
scores = {"수학" : [50, 45, 65, 70, 80],
"영어" : [90, 20, 55, 60, 75],
"과학" : [20, 15, 65, 90, 95]}
score_series = pd.Series(scores)
print(score_series)
print(dict(score_series))
시리즈가 자체으로 가지고 있는 함수들이 있다.
통계관련
grades = pd.Series([4.3, 3.7, 4.3, 3.3, 3.8, 4.2, 3.5, 2.3])
grades.name = "학점"
print(grades)
print(grades.mean())
print(grades.std())
print(grades.count())
print(grades.min())
print(grades.max())
print(grades.diff())
print(grades.describe())
print(grades.nonzero())
print(grades.notnull())
print(grades.isnull())
print(grades.nlargest())
print(grades.nsmallest())
s2 = pd.Series({"서울": 9631482, "부산": 3393191, "인천": 2632035, "대전": 1490158},
index=["부산", "서울", "인천", "대전"])
print(s2)
s2["대구"] = 1234567
print(s2)
s2["대구"] = 9999999
print(s2)
del s2["대구"]
print(s2)