Every line of 'drop nan from list python' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure.
52 def remove_negative(alist): 53 ''' 54 Args: 55 alist(list): a list of numbers may includes duplicates and negative 56 Returns: 57 list: a list of numbers may includes only duplicates, no negative and 0 58 ''' 59 60 ''' 61 Note: 62 When reading, 'alist' is a reference to the original 'list', and 'list[:]' 63 shallow-copies the list. 64 65 When assigning, 'alist' (re)binds the name and 'alist[:]' slice-assigns, 66 replacing what was previously in the list. 67 ''' 68 # filter seems not an in-place modification 69 # new_list = list(filter(lambda x: x > 0, alist)) 70 71 # following is not an in-place way either 72 # alist = [x for x in alist if x > 0] 73 74 # finally, this seems like an in-place operate as the id(alist) remains same 75 # correct me if I'm wrong 76 alist[:] = [x for x in alist if x > 0] 77 return alist
203 def nan_to_zero(segment: Union[pd.Series, list], nan_list: list) -> Union[pd.Series, list]: 204 if type(segment) == pd.Series: 205 for val in nan_list: 206 segment.values[val] = 0 207 else: 208 for val in nan_list: 209 segment[val] = 0 210 return segment
135 def replace_nan(value, default=0): 136 if math.isnan(value): 137 return default 138 return value