Understanding inplace=True

后端 未结 11 1036
遥遥无期
遥遥无期 2020-11-22 03:25

In the pandas library many times there is an option to change the object inplace such as with the following statement...

df.dropna(axis=\'index\         


        
11条回答
  •  南笙
    南笙 (楼主)
    2020-11-22 03:39

    The way I use it is

    # Have to assign back to dataframe (because it is a new copy)
    df = df.some_operation(inplace=False) 
    

    Or

    # No need to assign back to dataframe (because it is on the same copy)
    df.some_operation(inplace=True)
    

    CONCLUSION:

     if inplace is False
          Assign to a new variable;
     else
          No need to assign
    

提交回复
热议问题