■ DataFrame 클래스의 T 속성을 사용해 데이터를 전치하는 방법을 보여준다.
▶ 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 |
import pandas as pd import numpy as np dataFrame = pd.DataFrame( { "A" : 1.0, "B" : pd.Timestamp("20130102"), "C" : pd.Series(1, index = list(range(4)), dtype = "float32"), "D" : np.array([3] * 4, dtype = "int32"), "E" : pd.Categorical(["test", "train", "test", "train"]), "F" : "foo" } ) print(dataFrame) """ A B C D E F 0 1.0 2013-01-02 1.0 3 test foo 1 1.0 2013-01-02 1.0 3 train foo 2 1.0 2013-01-02 1.0 3 test foo 3 1.0 2013-01-02 1.0 3 train foo """ print() print(dataFrame.T) """ 0 1 2 3 A 1.0 1.0 1.0 1.0 B 2013-01-02 00:00:00 2013-01-02 00:00:00 2013-01-02 00:00:00 2013-01-02 00:00:00 C 1.0 1.0 1.0 1.0 D 3 3 3 3 E test train test train F foo foo foo foo """ |
▶ 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 명령을 실행했다.