python - Remove characters from the end of the data frame column values -


i have dataframe below values , want remove last characters i.e - row. how can it?

df:

sn  url 1   sunil- 2   r-amesh- 3   oxa-- 4   --ab 

i have below function, how apply this? is possible use lambda? please help?

def rchop(thestring, ending):     if thestring.str.endswith(ending):        return thestring[:-len(ending)]     return thestring  df['url'] = rchop(df['url'], '-') -- not working 

output expected:

sn  url 1   sunil 2   r-amesh 3   oxa 4   --ab 

we can use series.str.rstrip

in [16]: df['url'] = df['url'].str.rstrip('-')  in [17]: df out[17]:    sn      url 0   1    sunil 1   2  r-amesh 2   3      oxa 3   4     --ab 

Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

reflection - How to access the object-members of an object declaration in kotlin -

php - Doctrine Query Builder Error on Join: [Syntax Error] line 0, col 87: Error: Expected Literal, got 'JOIN' -