■ Series 클래스의 cumsum 메소드를 사용해 누적 합계를 구하는 방법을 보여준다.
▶ 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 45 46 47 48 49 50 51 |
import pandas as pd import numpy as np import matplotlib.pyplot as plt datetimeIndex = pd.date_range("2000/01/01", periods = 1000) series1 = pd.Series(np.random.randn(1000), index = datetimeIndex) print(series1) """ 2000-01-01 1.605094 2000-01-02 1.032125 2000-01-03 2.041472 2000-01-04 1.341634 2000-01-05 -0.410063 ... 2002-09-22 -1.272603 2002-09-23 1.260618 2002-09-24 -0.654690 2002-09-25 0.085590 2002-09-26 0.936237 Freq: D, Length: 1000, dtype: float64 """ print() series2 = series1.cumsum() print(series2) """ 2000-01-01 1.605094 2000-01-02 2.637219 2000-01-03 4.678692 2000-01-04 6.020325 2000-01-05 5.610263 ... 2002-09-22 17.052849 2002-09-23 18.313467 2002-09-24 17.658777 2002-09-25 17.744367 2002-09-26 18.680604 Freq: D, Length: 1000, dtype: float64 """ series2.plot() plt.show() |
▶ requirements.txt
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
contourpy==1.3.0 cycler==0.12.1 fonttools==4.54.1 kiwisolver==1.4.7 matplotlib==3.9.2 numpy==2.1.3 packaging==24.2 pandas==2.2.3 pillow==11.0.0 pyparsing==3.2.0 python-dateutil==2.9.0.post0 pytz==2024.2 six==1.16.0 tzdata==2024.2 |
※ pip install pandas matplotlib 명령을 실행했다.