■ Series 클래스의 생성자에서 index 인자와 dict 객체를 사용해 Series 객체를 만드는 방법을 보여준다.
▶ main.py
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 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
import pandas as pd dictionary1 = {"b" : 1, "a" : 0, "c" : 2} series1 = pd.Series(dictionary1) print(series1) print() """ b 1 a 0 c 2 dtype: int64 """ dictionary2 = {"a" : 0.0, "b" : 1.0, "c" : 2.0} series2 = pd.Series(dictionary2) print(series2) print() """ a 0.0 b 1.0 c 2.0 dtype: float64 """ series3 = pd.Series(dictionary2, index = ["b", "c", "d", "a"]) print(series3) print("-" *50) """" b 1.0 c 2.0 d NaN a 0.0 dtype: float64 """ |
▶ requirements.txt
1 2 3 4 5 6 7 8 |
numpy==2.1.3 pandas==2.2.3 python-dateutil==2.9.0.post0 pytz==2024.2 six==1.17.0 tzdata==2024.2 |
※ pip install pandas 명령을 실행했다.