0

I've seen lambda functions before but I've never written one myself until recently. I'm stumped on an error I got on a script.

Basically, what I'm doing is I have a file with hourly temperatures and wind speeds. From this file, I want to calculate wind chill. I got it to this point. The part I'm having trouble with is if the temperature is above 50°F, that entry is skipped. Here is my code and the error. Any help would be appreciated.

import pandas as pd
import numpy as np

data = pd.read_csv('KOKC.csv',header=6)

t = data['air_temp_set_1']
v = data['wind_speed_set_1']

wc = 35.74+0.6215*t-33.75*np.power(v,0.16)+0.4275*t*np.power(v,.16)
data['Wind Chill'] = wc.apply(lambda t: wc if t<50 else None)

data.to_csv('output.csv', index = False)

Traceback (most recent call last):
  File "C:\Users\David\Desktop\windchill.py", line 10, in <module>
    data['Wind Chill'] = wc.apply(lambda t: wc if t<50 else None)
  File "C:\Users\David\miniconda3\lib\site-packages\pandas\core\series.py", line 4357, in apply
    return SeriesApply(self, func, convert_dtype, args, kwargs).apply()
  File "C:\Users\David\miniconda3\lib\site-packages\pandas\core\apply.py", line 1043, in apply
    return self.apply_standard()
  File "C:\Users\David\miniconda3\lib\site-packages\pandas\core\apply.py", line 1107, in apply_standard
    return obj._constructor_expanddim(pd_array(mapped), index=obj.index)
  File "C:\Users\David\miniconda3\lib\site-packages\pandas\core\frame.py", line 700, in __init__
    dtype,
  File "C:\Users\David\miniconda3\lib\site-packages\pandas\core\internals\construction.py", line 483, in nested_data_to_arrays
    arrays, columns = to_arrays(data, columns, dtype=dtype)
  File "C:\Users\David\miniconda3\lib\site-packages\pandas\core\internals\construction.py", line 801, in to_arrays
    arr, columns = _list_of_series_to_arrays(data, columns)
  File "C:\Users\David\miniconda3\lib\site-packages\pandas\core\internals\construction.py", line 839, in _list_of_series_to_arrays
    index = ibase.default_index(len(s))
TypeError: object of type 'NoneType' has no len()

Thanks!

gtomer
  • 5,643
  • 1
  • 10
  • 21
David
  • 9
  • 2

0 Answers0