How to use 'pandas cast column to int' in Python

Every line of 'pandas cast column to int' 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
this disclaimer
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
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code


Related snippets