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 -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -