Strip Characters in Jupyter

Question:

I have what should be a simple problem. I have a lot of data which comes in the timestamp as below
I want to remove the values " +01" from the right hand side.

     Time
0 12/11/2021 09:26:02.001 +01
1 12/11/2021 09:26:02.021 +01

I am using the code below, but this also removes the .001 part of the first timestamp also

df=df.map(lambda x: x.rstrip(' +01')) 

Is there a simple way to do this?

Asked By: Keeks

||

Answers:

rstrip method deals with the provided strings as a list of characters to remove. It will remove any character (from the right side) that is within the string.

You can instead use regex:

import re
re.sub(r" +01", "", a)
Answered By: Jafar Isbarov
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.