3 examples of 'how to convert a pandas column to timedelta' in Python

Every line of 'how to convert a pandas column to timedelta' 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
207def decode_cf_timedelta(num_timedeltas, units):
208 """Given an array of numeric timedeltas in netCDF format, convert it into a
209 numpy timedelta64[ns] array.
210 """
211 num_timedeltas = np.asarray(num_timedeltas)
212 units = _netcdf_to_numpy_timeunit(units)
213 result = to_timedelta_unboxed(num_timedeltas.ravel(), unit=units)
214 return result.reshape(num_timedeltas.shape)
30def converter(df: DataFrame) -> Series:
31 return df[field_name]
107def _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

Related snippets