Understanding inplace=True

后端 未结 11 1107
遥遥无期
遥遥无期 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条回答
  •  -上瘾入骨i
    2020-11-22 03:30

    Yes, in Pandas we have many functions has the parameter inplace but by default it is assigned to False.

    So, when you do df.dropna(axis='index', how='all', inplace=False) it thinks that you do not want to change the orignial DataFrame, therefore it instead creates a new copy for you with the required changes.

    But, when you change the inplace parameter to True

    Then it is equivalent to explicitly say that I do not want a new copy of the DataFrame instead do the changes on the given DataFrame

    This forces the Python interpreter to not to create a new DataFrame

    But you can also avoid using the inplace parameter by reassigning the result to the orignal DataFrame

    df = df.dropna(axis='index', how='all')

提交回复
热议问题