I like to think every design decision is made for a reason. A lot of pandas functions (e.g. df.drop , df.rename df.replace) come with a parameter, inplace. If you set it to True, instead of returning a new dataframe, pandas modifies the dataframe, well, in place. No surprises here ;).
However, I often find my self using df.apply in combination with lambda expression to do somewhat more complex operations on columns. Consider the following example:
Say I have text data that needs to be pre-processed for sentiment analysis. I would use:
def remove_punctuation(text):
no_punct = "".join([c for c in text if c not in string.punctuation])
return no_punct
And then adapt my column as follows:
df['text'] = df['text'].apply(lambda x: remove_punctuation(x))
I recently noticed that .apply does not have an argument inplace=True. Since this function is mostly used to update dataframes, why is such an argument not available? What would be a rationale behind this?