I have a dataframe with multiple string columns. I want to use a string method that is valid for a series on multiple columns of the dataframe. Something like this is what I w
Function rstrip working with Series
so is possible use apply:
df = df.apply(lambda x: x.str.rstrip('f'))
Or create Series
by stack and last unstack:
df = df.stack().str.rstrip('f').unstack()
Or use applymap:
df = df.applymap(lambda x: x.rstrip('f'))
Last if need apply function to some columns:
#add columns to lists
cols = ['A']
df[cols] = df[cols].apply(lambda x: x.str.rstrip('f'))
df[cols] = df[cols].stack().str.rstrip('f').unstack()
df[cols] = df[cols].stack().str.rstrip('f').unstack()