본문 바로가기
반응형

개발 Tools/파이썬_Pandas & Numpy21

파이썬 Pandas count (열 갯수) count 열 별 값이 몇 개인지 알려준다. import pandas as pd df = pd.DataFrame([[0, 1, 2], [3, 4, 5]], index=["r0", "r1"], columns=["c0", "c1", "c2"]) print(df) 출력 c0 c1 c2 r0 0 1 2 r1 3 4 5 print(df.count()) 출력 c0 2 c1 2 c2 2 dtype: int64 2023. 2. 23.
파이썬 Pandas describe (통계정보) describe 전체 기술 통계 정보를 알려준다. import pandas as pd df = pd.DataFrame([[0, 1, 2], [3, 4, 5]], index=["r0", "r1"], columns=["c0", "c1", "c2"]) print(df) 출력 c0 c1 c2 r0 0 1 2 r1 3 4 5 print(df.describe()) 출력 c0 c1 c2 count 2.00000 2.00000 2.00000 mean 1.50000 2.50000 3.50000 std 2.12132 2.12132 2.12132 min 0.00000 1.00000 2.00000 25% 0.75000 1.75000 2.75000 50% 1.50000 2.50000 3.50000 75% 2.25000 3.25.. 2023. 2. 23.
파이썬 Pandas info (요약 정보) info 데이터 프래임의 전체 요약 정보를 알려준다 import pandas as pd df = pd.DataFrame([[0, 1, 2], [3, 4, 5]], index=["r0", "r1"], columns=["c0", "c1", "c2"]) print(df) 출력 c0 c1 c2 r0 0 1 2 r1 3 4 5 print(df.info()) 출력 Index: 2 entries, r0 to r1 Data columns (total 3 columns): # Column Non-Null Count Dtype --- ------ -------------- ----- 0 c0 2 non-null int64 1 c1 2 non-null int64 2 c2 2 non-null int64 dtypes: int6.. 2023. 2. 23.
파이썬 Pandas shape (행열 꼴) shape 데이터 프래임의 행열 꼴을 반환한다. 쉽게 말해, 몇 by 몇 행렬이냐 알 수 있다. df.shape[0] 하면, 행의 수, df.shape[1]하면 열의 수를 알 수 있다. import pandas as pd df = pd.DataFrame([[0, 1, 2], [3, 4, 5]], index=["r0", "r1"], columns=["c0", "c1", "c2"]) print(df) 출력 c0 c1 c2 r0 0 1 2 r1 3 4 5 print(df.shape) 출력 (2, 3) 2023. 2. 23.
파이썬 Pandas reset_index (행 초기화) reset_index 행 인덱스를 원래 값에서 0,1,2와 같이 초기화를 할 수 있다. 원래 있던 인덱스는 열로 들어간다. 행을 열로 바꿀 때 쓴다. import pandas as pd df = pd.DataFrame([[0, 1, 2], [3, 4, 5]], index=["r0", "r1"], columns=["c0", "c1", "c2"]) print(df) 출력 c0 c1 c2 r0 0 1 2 r1 3 4 5 df1 = df.reset_index() print(df1) 출력 index c0 c1 c2 0 r0 0 1 2 1 r1 3 4 5 2023. 2. 23.