- you have more room to comment what the intention of the code/call is
- you have room to handle / check for errors
For example, the "sort_values" and "groupby" in you example are obvious most readers. But "transform("cumsum") is probably obvious to you but I don't know the intention of the code.
By reassigning to df it makes it clear that the returned value from each of the functions is a `df` (some kind of query builder I think). Actually rewriting you r code I discovered your groupby did a groupby and then selected a result column I think.
So we would get:
// sort result on dependency date
df = df.sort_values('dep_date')
// ... check if sort_values worked (i.e `dep_date` is valid column)
// group result by name and select duration column
durations = df.groupby('name')['duration']
// compute columns cumulative sum of durations
sum = durations.transform('cumsum')
I agree its much more verbose, so this won't work if you (just) want conciseness.