■ DataFrame 클래스의 mean 메소드를 사용해 각 컬럼의 평균값을 구하는 방법을 보여준다.
▶ 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 |
import pandas as pd import numpy as np datetimeIndex = pd.date_range("20130101", periods = 6) dataFrame = pd.DataFrame(np.random.randn(6, 4), index = datetimeIndex, columns = list("ABCD")) print(dataFrame) """ A B C D 2013-01-01 -0.427331 -0.372399 0.195643 -0.280798 2013-01-02 0.788336 -0.135781 -0.407083 -0.411756 2013-01-03 -1.350004 -1.162144 -0.036725 0.311316 2013-01-04 -1.433128 -0.333235 2.136542 1.440727 2013-01-05 -0.579444 -0.868167 0.041668 0.019251 2013-01-06 -0.576273 1.069613 1.486077 -1.053925 """ print() series = dataFrame.mean() print(series) """ A -0.596307 B -0.300352 C 0.569354 D 0.004136 dtype: float64 """ |
▶ requirements.txt
1 2 3 4 5 6 7 8 |
numpy==2.1.2 pandas==2.2.3 python-dateutil==2.9.0.post0 pytz==2024.2 six==1.16.0 tzdata==2024.2 |
※ pip install pandas 명령을 실행했다.