Why? To save keystrokes (important in itself). However, it also reduces the probability of silly errors like typing the name of the object wrong in one place.
Example: I wanted to drop a row because it was added in the original dataset by an error. I wrote:
cost_in_age = cost_in_age.drop(cost_in_age.index[105])
A shorter way, which does not work now, but is equally (or more) intuitive, would be:
cost_in_age.drop(cost_in_age.index[105])
Sometimes it is possible to do the latter, but then one has to specify that it is to be done "inplace". So when we do something with objects we should not have to specify this.
OK, I know there are probably good reasons why it is like this. Methods and functions return things and unless it is explicitly specified they we should put the output returned in an object, it is simply just returned.
But still, it does not look technically impossible to make it the other way. Inplace as standard? Benefits would be a lot of saved typing and reduced errors. Cost?
No comments:
Post a Comment