Why this code gives AttributeError?

cols = list(df.columns)

df= df.sort_values(by=cols, inplace=True, na_position='first', ignore_index=True)

df.head()

Gives AttributeError: ‘NoneType’ object has no attribute ‘head’. Please guide.

remove df =
When you add inplace=True you don’t need to reassign the variable.