Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/277.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 在带有异常值的数据报中使用min()函数_Python_Pandas - Fatal编程技术网

Python 在带有异常值的数据报中使用min()函数

Python 在带有异常值的数据报中使用min()函数,python,pandas,Python,Pandas,我在pandas数据帧中使用min()函数,目的是获取最小值 但是,在DataFrame中,所有“坏数据”值都已替换为-9999999 如何在min()函数中忽略该值?该值不携带数据值 下面是一些代码: # the for I, row loop is designed to identify which rows are data rows and which rows are not. the bottom portion filters out non-data rows. xl =

我在pandas数据帧中使用min()函数,目的是获取最小值

但是,在DataFrame中,所有“坏数据”值都已替换为-9999999

如何在min()函数中忽略该值?该值不携带数据值

下面是一些代码:

# the for I, row loop is designed to identify which rows are data rows and which rows are not.  the bottom portion filters out non-data rows.  
xl = pd.read_excel(location, header=None, sheet_name=0)
keep = []
for i, row in xl.iterrows():
    cells = 0
    numbers = 0
    for j, column in row.iteritems():
        cells += 1
        if type(column).__name__ in ('float', 'int') and not pd.isnull(column):
            numbers += 1
        #print(i,column)
    #print(i, cells, numbers, numbers/cells*100)
    if numbers/cells*100 > 50:
        keep.append(i)


#filters out those records that are most likely NOT data rows
df = xl.iloc[keep]
#apply's -9999999 default value to conform to data type standards
df = df.apply(lambda x: pd.to_numeric(x, errors='coerce')).fillna(-9999999)

# ToDo: Ignore -9999999 when performing the below functions
dfmax = df.max()
dfmin = df.min()
谢谢


警告:如果我不符合默认值,则min()和max()函数不会报告所有记录的值,因为该列将是混合数据类型。

解决方案是获取超过该数字的值:

df.values[df.values > -9999999].min()

通常,Numpy不是一个数字。nan是坏数据的最佳表示,而不是实际的数值,在Pandas v>0.15中,它将NULL写入SQL。

解决方案是获取该数字上的值:

df.values[df.values > -9999999].min()

一般来说,Numpy不是一个数字。nan是坏数据的最佳表示形式,而不是实际的数值,在Pandas v>0.15中,它将NULL写入SQL。

您能在这里添加实际代码吗?坏数据可能位于整列和整行,还是单个单元格?举一个数据示例会有所帮助。我要做的第一件事是消除数据帧中的非数据行。然后我在列中查找坏的单元格。类似于
dfmin=df.values[df.values>-9999999]).min()之类的内容。您能在这里添加实际的代码吗?坏数据可能位于整个列和行中,还是单个单元格?举一个数据示例会有所帮助。我要做的第一件事是消除数据帧中的非数据行。然后我在列中查找坏单元格。类似于
dfmin=df.values[df.values>-999999]).min()
?np.nan如何处理.to_sql?它是否设置为空?难道不是
nsmallest
只会给你
-9999999
两次吗?和
df[df.values>-9999999].min()
也不做你想做的事,如果有什么
df.values[df.values>-9999999].min()
..@acree123
np.nan
输出NULL到sql。非常感谢!这很有效。numpy和panda之间有很多东西需要学习。np.nan如何与.to_sql一起工作?它是否设置为空?难道不是
nsmallest
只会给你
-9999999
两次吗?和
df[df.values>-9999999].min()
也不做你想做的事,如果有什么
df.values[df.values>-9999999].min()
..@acree123
np.nan
输出NULL到sql。非常感谢!这很有效。numpy和panda之间有很多东西需要学习。