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?
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)
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?
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)