티스토리 뷰

read_excel

data_frame: DataFrame = pd.read_excel("C:\\example\\ex.xlsx")

excel 파일을 읽어오기

 

header

data_frame: DataFrame = pd.read_excel("C:\\example\\ex.xlsx", header=[0,1,2,3])
음식 떡볶이
샐러드
불고기
파스타

컬럼이 (떡볶이, 샐러, 불고기, 파스타)가 됨

 

stack

body_dataframe : DataFrame = body_dataframe.stack(level=[0,1,2])
>>> df_multi_level_cols1
     weight
         kg    pounds
cat       1        2
dog       2        4
>>> df_multi_level_cols1.stack()
            weight
cat kg           1
    pounds       2
dog kg           2
    pounds       4

 

reset_index

body_dataframe.reset_index(inplace=True)
>>> df
         class  max_speed
falcon    bird      389.0
parrot    bird       24.0
lion    mammal       80.5
monkey  mammal        NaN
>>> df.reset_index()
    index   class  max_speed
0  falcon    bird      389.0
1  parrot    bird       24.0
2    lion  mammal       80.5
3  monkey  mammal        NaN

 

inplace = False: 명령어를 실행 한 후 메소드가 적용된 데이터 프레임을 기존 데이터 프레임으로 대체

 

inplace = True:  명령어를 실행 한 후 메소드가 적용된 데이터 프레임으로 반환

즉, 삭제 메소드를 실행했다면 반환값은 컬럼이 삭제된 Dataframe이 됨

공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/07   »
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
글 보관함