while learning through SO's one of the question, where using regex to extract values.
I am wondering how we can implement a regex to remove all the characters if the are same in every row and matching the same index position.
Below is the DataFrame:
print(df)
column1
0 [b,e,c]
1 [e,a,c]
2 [a,b,c]
regex :
df.column1.str.extract(r'(\w,\w)')
print(df)
column1
0 b,e
1 e,a
2 a,b
In the above regex it extract the characters needed but i want to preserve [] this as well.
column1? Do you actually have'[b,e,c]'there?column1, trydf['column1'].str.replace(r'\[(\w,\w).*', r'[\1]', regex=True)sre_constants.error: unterminated character set at position 0[