Since this has the nature of a command, I would probably format it close to your example, like this:
df.groupby[['x','y']] \
.apply(lambda x: np.max(x['z'])-np.min(x['z'])) \
.sort_values(ascending=False)
It took me a long time to realize I could break these expressions before the dots, which is often more readable than breaking inside the parentheses (same goes for "some long string".format()).
If this were more like an expression evaluation, I'd wrap the whole thing in parentheses, which is considered more "Pythonic" than line continuation markers:
var = (
df.groupby[['x','y']]
.apply(
lambda x: np.max(x['z'])-np.min(x['z'])
)
.sort_values(ascending=False)
)
Update Since writing this, I've moved away from backslashes for line continuation whenever possible, including here, where it's not meaningful to chain the operations without assigning it to a variable or passing it to a function. I've also switched to using one level of indentation for each level of nesting inside parentheses or brackets, to avoid going to deep and/or getting a wiggly effect. So I would now write your expression like this:
var = (
df
.groupby[['x','y']]
.apply(
lambda x: np.max(x['z']) - np.min(x['z'])
)
.sort_values(ascending=False)
)