How to remove rows containing outliers in Python?

To remove rows with outliers, you can use the following code:

import pandas as pd

# 创建DataFrame示例数据
data = {'col1': [1, 2, 3, 4, 5],
        'col2': [6, 7, 8, 9, 10]}
df = pd.DataFrame(data)

# 删除col2列中大于8的异常值所在行
df = df[df['col2'] <= 8]

In the code above, we first create a DataFrame object df, and then filter out the rows in column col2 that are not greater than 8, essentially removing the rows with outliers.

Please note that the above code is only applicable for data processing with the pandas library. If you are using a different data processing library, there may be different methods to remove rows with outliers.

Leave a Reply 0

Your email address will not be published. Required fields are marked *


广告
Closing in 10 seconds
bannerAds