如果inplace=True通过,该数据被重命名到位(它没有返回值),所以你会使用:df.an_operation(inplace=True)当inplace=False传递(这是默认值,所以没有必要),执行操作,并返回该对象的副本,所以你会使用:df = df.an_operation(inplace=False) 所以:if inplace == False: Assign your result to a new variableelse No need to assign
我使用它的方式是# Have to assign back to dataframe (because it is a new copy)df = df.some_operation(inplace=False) 要么# No need to assign back to dataframe (because it is on the same copy)df.some_operation(inplace=True)结论: if inplace is False Assign to a new variable; else No need to assign