python中是否有解决“结果过大”的方法?

时间:2019-12-03 17:45:28

标签: python pandas

这是python中的一个程序,使用libray熊猫,根据其余数据的值将不同的值分配给新列。它适用于小数据,但是由于某些原因,当我尝试对大数据使用程序时,它会失败并显示错误。我尝试了库decimal,但是它不起作用。我认为该错误与float的大小有关,但我找不到解决它的方法。谢谢

错误:

runfile('C:/Users/Usuario/Documents/DOCUMENTOS Y DATOS/ESTUDIO/4. TFM/Task 1/TASK SIN FILTRADO/TASK 3.4 sf.py', wdir='C:/Users/Usuario/Documents/DOCUMENTOS Y DATOS/ESTUDIO/4. TFM/Task 1/TASK SIN FILTRADO')
Traceback (most recent call last):

  File "<ipython-input-34-37348501d189>", line 1, in <module>
    runfile('C:/Users/Usuario/Documents/DOCUMENTOS Y DATOS/ESTUDIO/4. TFM/Task 1/TASK SIN FILTRADO/TASK 3.4 sf.py', wdir='C:/Users/Usuario/Documents/DOCUMENTOS Y DATOS/ESTUDIO/4. TFM/Task 1/TASK SIN FILTRADO')

  File "C:\Users\Usuario\Anaconda3\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 827, in runfile
    execfile(filename, namespace)

  File "C:\Users\Usuario\Anaconda3\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 110, in execfile
    exec(compile(f.read(), filename, 'exec'), namespace)

  File "C:/Users/Usuario/Documents/DOCUMENTOS Y DATOS/ESTUDIO/4. TFM/Task 1/TASK SIN FILTRADO/TASK 3.4 sf.py", line 76, in <module>
    table["Flow_pattern"] = table.apply(lambda x: flow_pattern(x["Fcoef"], x["Vcoef"]), axis=1)

  File "C:\Users\Usuario\Anaconda3\lib\site-packages\pandas\core\frame.py", line 6913, in apply
    return op.get_result()

  File "C:\Users\Usuario\Anaconda3\lib\site-packages\pandas\core\apply.py", line 186, in get_result
    return self.apply_standard()

  File "C:\Users\Usuario\Anaconda3\lib\site-packages\pandas\core\apply.py", line 292, in apply_standard
    self.apply_series_generator()

  File "C:\Users\Usuario\Anaconda3\lib\site-packages\pandas\core\apply.py", line 321, in apply_series_generator
    results[i] = self.f(v)

  File "C:/Users/Usuario/Documents/DOCUMENTOS Y DATOS/ESTUDIO/4. TFM/Task 1/TASK SIN FILTRADO/TASK 3.4 sf.py", line 76, in <lambda>
    table["Flow_pattern"] = table.apply(lambda x: flow_pattern(x["Fcoef"], x["Vcoef"]), axis=1)
  File "C:/Users/Usuario/Documents/DOCUMENTOS Y DATOS/ESTUDIO/4. TFM/Task 1/TASK SIN FILTRADO/TASK 3.4 sf.py", line 35, in flow_pattern
    fun=e**((Vcoef+59627)/8432.5)

OverflowError: (34, 'Result too large', 'occurred at index 206')

代码:


import pandas as pd

e=2.71828182845904523536
table = pd.read_csv('Coef_Data_sf.csv', sep = ',', header = 0)
flowmap = pd.read_csv('flow_map.csv', sep = ',', header = 1)

flowmaptag =  pd.read_csv('flow_map.csv', sep = ',', header = 0)
986

# X - F COEF             Y - V COEF
# ANNU WISPY y = 8432,5*ln(x) - 59627
# CHURN SLUG y = 9,604ln(x) - 29,739
# BUbblY SLUG y = 462514x-1,29



def flow_pattern(Fcoef, Vcoef):


    if Vcoef>100:
        fun=e**((Vcoef+59627)/8432.5)
        if Fcoef<fun:
            return "Annular"
        elif Fcoef>fun:
            return "Wispy_annular"
        else:
            return "error1"

    elif 48<Vcoef<100:
         if Fcoef<5070:
             return "Churn"
         elif Fcoef>5070:
             return "Bubbly"

    elif 10<Vcoef<48:
        fun1=e**((Vcoef+29.739)/9.604)
        if Fcoef<fun1:
            return "Churn"
        elif fun1<Fcoef<5070:
            return "Slug"
        elif 5070<Fcoef:
            return "Bubbly"
        else:
            return "error2"

    elif Vcoef<10:
        fun1=e**((Vcoef+29.739)/9.604)
        fun2=e**((Vcoef+1.29)/462514)
        if Fcoef<fun1:
            return "Churn"
        elif fun1<Fcoef<fun2:
            return "Slug"
        elif fun2<Fcoef:
            return "Bubbly"
        else:
            return "error3"

    else:
        return "errorfin"


table["Flow_pattern"] = table.apply(lambda x: flow_pattern(x["Fcoef"], x["Vcoef"]), axis=1)

table.to_csv('Data_with_flowpattern_sf.csv')

0 个答案:

没有答案