假设我有一个熊猫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++']]})
如果我想将R[space]
的{{1}}和R,
替换为R
的{{1}}和C[space]
,应该怎么做?
答案 0 :(得分:2)
使用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++]