如何从字符串python pandas中提取数字和字符?
我有一个混合数字数据和字符数据的数据集。我只想提取数值数据和字母“ w”(我不需要'2 x hdmi | 2 x usb'....)。
在这种情况下(20 W,30W等)。 感谢您的帮助
v=['2 x HDMI | 2 x USB', '20 W Speaker Output', '10 W Speaker Output',
'20 W Speaker Output', '20 W Speaker Output',
'20 W Speaker Output', '20 W Speaker Output', '20 Speaker Output',
'20 W Speaker Output', '20 W Speaker Output',
'30 W Speaker Output', '20 W Speaker Output',
'20 W Speaker Output', '2 x HDMI | 2 x USB', '20 W Speaker Output',
'20 Speaker Output', '24 W Speaker Output', '20 W Speaker Output']
df=pd.DataFrame({"col_1":v})
I have a dataset that mixes numeric and character data. I would like to extract only the numerical data and letter "W" (i don't need '2 x HDMI | 2 x USB'....) .
for exemple in this case (20 W, 30W etc).
thank you for your help
v=['2 x HDMI | 2 x USB', '20 W Speaker Output', '10 W Speaker Output',
'20 W Speaker Output', '20 W Speaker Output',
'20 W Speaker Output', '20 W Speaker Output', '20 Speaker Output',
'20 W Speaker Output', '20 W Speaker Output',
'30 W Speaker Output', '20 W Speaker Output',
'20 W Speaker Output', '2 x HDMI | 2 x USB', '20 W Speaker Output',
'20 Speaker Output', '24 W Speaker Output', '20 W Speaker Output']
df=pd.DataFrame({"col_1":v})
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以使用正则表达式和一些列表理解骗局来获得所需的东西:
...导致:
You can use regular expressions and a little bit of list comprehension trickery to get what you desire:
... results in:
尝试:
Try:
上述提取方法与正则曲目,将按预期过滤,然后清除NAN值。
This above extract method with regex, will filter as expected, then clear Nan value.