如何从给定的数据帧列中删除所有字符串?
我需要在Python中预处以用于机器学习的列。该列包含一系列的1和0(这是所需的输出),但是其中有一些字符串需要删除['px7','d1'等。]
我考虑过将DF.Replace用于用np.nan替换字符串,然后使用df.dropna()将其删除。我想知道这样做的标准方法是什么,因为这可能是一项非常常见的预处理任务。
I need to preprocess a column for machine learning in python. The column contains a series of 1s and 0s (which is the desired output), but there are some strings in there that needs to be removed ['PX7','D1', etc..]
I thought about using df.replace to replace the strings with np.nan and then using df.dropna() to remove it. I was wondering what is the standard way of doing this given that this is probably a very common preprocessing task.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用:
或者,转换为数字以保持所有数字:
然后,您可以使用
dropna
(如果需要)。You can use:
Or, convert to numeric to keep all numbers:
Then you can use
dropna
the way you want (if needed).使用:
输入:
输出:
Use:
Input:
Output:
Second approch: