본문 바로가기
반응형

일단 제가 준비한 건,262

파이썬 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.
파이썬 Pandas reindex (행 지정, 행 변경) reindex 인덱스를 새로 지정할 수 있다. 기존의 행 이름과 다른 인덱스를 부여하면 NaN로 채워진다. 다른 숫자로 채우고 싶으면 fill_value= 를 지정해주면 된다. 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 index를 변경해 줬기 때문에 값도 변한다. 이름을 바꾸고 싶다면, rename을 쓰면 된다. 이름이 동일 하다면, 값을 그대로다. new_index = ["R0", "R1", "R2"] df1 = df.reindex(new_index) print(df1) 출력 c.. 2023. 2. 23.