Reputation: 669
Suppose I have a pandas df:
import pandas as pd
ex = pd.DataFrame({'Title': ['Data Scientist', 'Data Analyst', 'Data Engineer'],
'Skills': [['Python', 'R ', 'C ', 'C++'], ['Python', 'R,', 'C ', 'C++'], ['Python', 'R ', 'C,', 'C++']]})
If I want to replace R[space]
and R,
with R
and C[space]
and C,
with C
, how should I do it?
Upvotes: 0
Views: 869
Reputation: 323326
Using strip
ex.Skills=[[y.strip() for y in x] for x in ex.Skills]
ex
Out[755]:
Title Skills
0 Data Scientist [Python, R, C, C++]
1 Data Analyst [Python, R, C, C++]
2 Data Engineer [Python, R, C, C++]
Upvotes: 2