inplace=True
makes the function impure. It changes the original dataframe and returns None. In that case, You breaks the DSL chain.
Because most of dataframe functions return a new dataframe, you can use the DSL conveniently. Like
df.sort_values().rename().to_csv()
Function call with inplace=True
returns None and DSL chain is broken. For example
df.sort_values(inplace=True).rename().to_csv()
will throw NoneType object has no attribute 'rename'
Something similar with python’s build-in sort and sorted. lst.sort()
returns None
and sorted(lst)
returns a new list.
Generally, do not use inplace=True
unless you have specific reason of doing so. When you have to write reassignment code like df = df.sort_values()
, try attaching the function call in the DSL chain, e.g.
df = pd.read_csv().sort_values()...