2024-04-25 23:58:38 发布
网友
对Python和熊猫完全陌生。提前感谢您的帮助!在
我有一个熊猫数据帧:
In [8]: test Out[8]: Product Price 0 A (BC) 12 1 ABC12 34 2 CD12 (EFG) 56
我试图删除左括号后的任何内容以及产品名称中的数字。基本上,我想要:
我试着用test['Product']。结构分裂(“(”)[0]但它不起作用。在
试试看
test['Product'] = test['Product'].str.extract('([a-zA-Z]+)')
一种可能的解决方案是将括号中的^{}内容清空string,然后^{}:
string
df.Product = df.Product.str.replace(r"\((.*)\)", "").str.extract("([A-Z]+)", expand=False) print (df) Product Price 0 A 12 1 ABC 34 2 CD 56
试试看
test['Product'] = test['Product'].str.extract('([a-zA-Z]+)')
一种可能的解决方案是将括号中的^{} 内容清空} :
string
,然后^{相关问题 更多 >
编程相关推荐