Python error: unsupported operand type(s) for -: 'float' and 'NoneType'

Rocco Rinaldi-Rose

My code is supposed to read and subtract two data lists from each other. Why am I receiving this error, and how can I resolve it?

Here is the full error:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "spectra.py", line 32, in SpectraTest
    subt = map(sub, flux, flux1)
TypeError: unsupported operand type(s) for -: 'float' and 'NoneType'

Here is the code:

import csv

def SpectraTest():
    wave_num = []
    flux = []
    wave_num1=[]
    flux1 = []
    with open ("H20_Glass.CSV", "rb") as csvfile:
        datareader= csv.reader(csvfile, delimiter = ",")
        for row in datareader:
            tempdata = row
            wn = tempdata[0]
            f1 = tempdata [1]
            wn = eval(wn)
            f1 = eval(f1)
            wave_num.append(wn)
            flux.append(f1)

    with open ("blankGlass.CSV", "rb") as csvfile:
        datareader= csv.reader(csvfile, delimiter = ",")
        for row in datareader:
            tempdata1 = row
            wn1 = tempdata1[0]
            f2 = tempdata1[1]
            wn1 = eval(wn1)
            f2 = eval(f2)
            wave_num1.append(wn1)
            flux1.append(f2)
        map(float, flux1)
        map(float, flux)
        from operator import sub
        subt = map(sub, flux, flux1)
        wave_num1.reverse()
        wave_num.reverse()
        print("Number of wave numbers " + str(len(wave_num1)))
        print("Number of flux numbers = "+ str(len(flux1)))

        print("Number of wave numbers " + str(len(wave_num)))
        print("Number of flux numbers = "+ str(len(flux)))
        print subt
    csvfile.close()
Holloway

From the Python docs:

map(function, iterable, ...)

...If one iterable is shorter than another it is assumed to be extended with None items...

I'd guess that your lists are not the same length so that it's trying to subtract a None from a float.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Unsupported operand types 'NoneType'

From Dev

Python TypeError: unsupported operand type(s) for /: 'NoneType' and 'float'

From Dev

TypeError: unsupported operand type(s) for +=: 'float' and 'NoneType' in Python 3

From Dev

unsupported operand types for * : 'float' and 'decimal'

From Dev

Python Error: unsupported operand type(s) for +: 'int' and 'NoneType'

From Dev

Python Error: unsupported operand type(s) for +: 'int' and 'NoneType'

From Dev

TypeError: unsupported operand type(s) for /: 'NoneType' and 'float'

From Dev

Unsupported operand type(s) for *: 'NoneType' and 'NoneType' (Python)

From Dev

TypeError: unsupported operand int and NoneType? Python

From Dev

Python Type Error Unsupported Operand

From Dev

Unsupported operand type(s) for +: 'float' and 'str' error

From Dev

Python: unsupported operand type(s) for /: 'tuple' and 'float'

From Dev

Unsupported operand types for bitwise exclusive OR in Python

From Dev

Django unsupported operand types

From Dev

Python TypeError: unsupported operand type(s) for +: 'NoneType' and 'str'

From Dev

Unsupported operand in if/else statement error in Python

From Dev

Unsupported operand types error when declaring default params as INF

From Dev

Why following codes shows Unsupported operand types error?

From Dev

Python TypeError: unsupported operand type(s) for ^: 'float' and 'int'

From Dev

Python 3: unsupported operand type(s) for /: 'float' and 'bytes'

From Dev

Type error: unsupported operand

From Dev

unsupported operand types for //: 'str', 'int'

From Dev

Unsupported operand type in Python

From Dev

unsupported operand type(s) for +=: 'NoneType' and 'list'

From Dev

unsupported operand type(s) for +: 'NoneType' and 'int'

From Dev

TypeError: unsupported operand type(s) for *: 'NoneType' and 'int'

From Dev

TypeError: unsupported operand type(s) for +: 'NoneType' and 'str'

From Dev

TypeError: unsupported operand type(s) for +: 'int' and 'NoneType'

From Dev

TypeError: unsupported operand type(s) for %: 'NoneType' and 'int'

Related Related

  1. 1

    Unsupported operand types 'NoneType'

  2. 2

    Python TypeError: unsupported operand type(s) for /: 'NoneType' and 'float'

  3. 3

    TypeError: unsupported operand type(s) for +=: 'float' and 'NoneType' in Python 3

  4. 4

    unsupported operand types for * : 'float' and 'decimal'

  5. 5

    Python Error: unsupported operand type(s) for +: 'int' and 'NoneType'

  6. 6

    Python Error: unsupported operand type(s) for +: 'int' and 'NoneType'

  7. 7

    TypeError: unsupported operand type(s) for /: 'NoneType' and 'float'

  8. 8

    Unsupported operand type(s) for *: 'NoneType' and 'NoneType' (Python)

  9. 9

    TypeError: unsupported operand int and NoneType? Python

  10. 10

    Python Type Error Unsupported Operand

  11. 11

    Unsupported operand type(s) for +: 'float' and 'str' error

  12. 12

    Python: unsupported operand type(s) for /: 'tuple' and 'float'

  13. 13

    Unsupported operand types for bitwise exclusive OR in Python

  14. 14

    Django unsupported operand types

  15. 15

    Python TypeError: unsupported operand type(s) for +: 'NoneType' and 'str'

  16. 16

    Unsupported operand in if/else statement error in Python

  17. 17

    Unsupported operand types error when declaring default params as INF

  18. 18

    Why following codes shows Unsupported operand types error?

  19. 19

    Python TypeError: unsupported operand type(s) for ^: 'float' and 'int'

  20. 20

    Python 3: unsupported operand type(s) for /: 'float' and 'bytes'

  21. 21

    Type error: unsupported operand

  22. 22

    unsupported operand types for //: 'str', 'int'

  23. 23

    Unsupported operand type in Python

  24. 24

    unsupported operand type(s) for +=: 'NoneType' and 'list'

  25. 25

    unsupported operand type(s) for +: 'NoneType' and 'int'

  26. 26

    TypeError: unsupported operand type(s) for *: 'NoneType' and 'int'

  27. 27

    TypeError: unsupported operand type(s) for +: 'NoneType' and 'str'

  28. 28

    TypeError: unsupported operand type(s) for +: 'int' and 'NoneType'

  29. 29

    TypeError: unsupported operand type(s) for %: 'NoneType' and 'int'

HotTag

Archive