Name ID
0 [Name1] 1
1 [Name2] 2
2 [Name3] 3
/home/sawik/./playground.py:81: FutureWarning: The default value of regex will change from True to False in a future version. In addition, single character regular expressions will *not* be treated as literal strings when regex=True.
df['Name'] = df['Name'].str.replace("[", "")
/home/sawik/./playground.py:82: FutureWarning: The default value of regex will change from True to False in a future version. In addition, single character regular expressions will *not* be treated as literal strings when regex=True.
df['Name'] = df['Name'].str.replace("]", "")
Name ID
0 Name1 1
1 Name2 2
2 Name3 3
3条答案
按热度按时间fxnxkyjh1#
你的列由列表组成,而不是字符串,所以你不能对它使用字符串操作。你 * 可以 *(并且应该)做的是将字符串列表
.join
为用逗号分隔的字符串。pkln4tw62#
代码中有错误,即
'
(单引号)字符。请尝试以下操作:返回:
xxls0lw83#
这应该有帮助,你需要使用字符来解决问题