Python

[Jupyter Notebook] FutureWarning: The frame.append method is deprecated and will be removed from pandas in a future version. (후략)

xojuholic 2022. 11. 25.
728x90
반응형

제목과 같은 Warning 메시지를 확인한 코드는 아래와 같다.

import pandas as pd

data = {
    'name' : ['영수','철수','영희','소희'],
    'age' : [20,15,38,8]
}

df = pd.DataFrame(data)

doc = {
    'name':'세종',
    'age':14,
}

df = df.append(doc,ignore_index=True)

df

 

상기 코드로 발생한 Warning 메시지 원문은 아래와 같다.

FutureWarning: The frame.append method is deprecated and will be removed from pandas in a future version. Use pandas.concat instead.
  df = df.append(doc,ignore_index=True)

 

Warning 메시지를 잘 보면, .append method가 곧 deprecated 된다는 내용이며 대체 method로 pandas.concat method를 사용하라고 명기하고 있다. 그래서 해당 코드는 아래와 같이 바꿔주면 된다. 물론 dictionary 형태를 data frame 형태로 전환해주기 위해서는 Jupyter Notebook의 엄격한 Syntax 통과를 위해서 약간의 수정도 병행해줘야 한다.

import pandas as pd

data = {
    'name' : ['영수','철수','영희','소희'],
    'age' : [20,15,38,8]
}

df1 = pd.DataFrame(data)

doc = {
    'name': ['세종'],   # 약간의 수정
    'age': [14],        # 약간의 수정
}

df2 = pd.DataFrame(doc)

df = pd.concat([df1, df2], ignore_index = False)

df

 

728x90
반응형
SMALL

댓글

💲 추천 글