4 examples of 'convert object to float pandas' in Python

Every line of 'convert object to float pandas' 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.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
175def conv_to_float(self,obj):
176 try:
177 float_obj = float(obj)
178 return float_obj, True
179 except ValueError:
180 return None, False
55def _to_np_float64(v):
56 if math.isnan(v) or math.isinf(v):
57 return np.inf
58 return np.float64(v)
91def is_float(obj):
92 """
93 Valid types are:
94 - objects of float type
95 - Strings that can be converted to float. For example '1e-06'
96 """
97 is_f = isinstance(obj, float)
98 if not is_f:
99 try:
100 float(obj)
101 is_f = True
102 except (ValueError, TypeError):
103 is_f = False
104 return is_f and not is_bool(obj)
39def as_float_array(X, copy=True):
40 """Converts an array-like to an array of floats
41
42 The new dtype will be np.float32 or np.float64, depending on the original
43 type. The function can create a copy or modify the argument depending
44 on the argument copy.
45
46 Parameters
47 ----------
48 X : array
49
50 copy : bool, optional
51 If True, a copy of X will be created. If False, a copy may still be
52 returned if X's dtype is not a floating point type.
53
54 Returns
55 -------
56 X : array
57 An array of type np.float
58 """
59 if isinstance(X, np.matrix):
60 X = X.A
61 elif not isinstance(X, np.ndarray) and not sparse.issparse(X):
62 return safe_asarray(X, dtype=np.float64)
63 if X.dtype in [np.float32, np.float64]:
64 return X.copy() if copy else X
65 if X.dtype == np.int32:
66 X = X.astype(np.float32)
67 else:
68 X = X.astype(np.float64)
69 return X

Related snippets