用Python中的IQR排除异常值吗?

时间:2019-06-24 08:07:48

标签: python pandas numpy

我尝试排除Python中的异常值。如何计算price_int_eu的IQR并排除异常值的结果对象(我删除了结果对象的其他键,但这样做很有意义)?

json的示例:

[{
        "objectID": 12736,

        "results": [
            {
                "price_int": null
            },
            {
                "price_int": 50372
            },
            {
                "price_int": 51930
            },
            {
                "price_int": 58824
            },
            {
                "price_int": 12542
            }
        ]
    }]

我在for循环中尝试过使用此功能:

for i in data:
import json
import numpy as np

with open('./input/output_db_gm.json', encoding='utf-8') as data_file:
    data = json.loads(data_file.read())

    for i in data:
        results = i["results"]

        if not results == []:
            price_int = [x["price_int"] for x in results]
            price_int = [x for x in price_int if x is not None]
            if not price_int == []:
                quartile_1, quartile_3 = np.percentile(price_int)
                iqr = quartile_3 - quartile_1
                lower_bound = quartile_1 - (iqr * 1.5)
                upper_bound = quartile_3 + (iqr * 1.5)
                prices_iqr = np.where((price_int > upper_bound) | (price_int < lower_bound))
                print(prices_iqr)

        else:
            pass

但是我不确定我要去哪里,这没有用。 我有一个TypeError: percentile() missing 1 required positional argument: 'q'

0 个答案:

没有答案