Every line of 'convert float to int python 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.
6 def convert_string_to_float_int(string): 7 8 if isinstance(string, six.string_types): 9 try: 10 # evaluate the string to float, int or bool 11 value = literal_eval(string) 12 except Exception: 13 value = string 14 else: 15 value = string 16 17 # check if the the value is float or int 18 if isinstance(value, float): 19 if value.is_integer(): 20 return int(value) 21 return value 22 return value
107 def _time_cols_to_ints(df, columns=None, nat_value=SMALLDT64): 108 """ 109 Converts all datetime columns to ints. 110 111 Previously NaT were convertible to ints, but now they raise a value error. 112 We need, therefore, to designate a time that will be used as NaT. 113 """ 114 cols = columns or df.select_dtypes(include=["datetime64"]).columns 115 df.loc[:, cols] = df.loc[:, cols].fillna(nat_value).astype(np.int64) 116 return df