I have this Int Columns below:
import pandas as pd
import numpy as np
dplyr_1.dtypes
year int64
dplyr int64
data.table int64
pandas int64
apache-spark int64
dtype: object
Convert the Int column to string:
dplyr_1.year = dplyr_1.year.astype(str)
dplyr_1.dtypes
year object
dplyr int64
data.table int64
pandas int64
apache-spark int64
dtype: object
Make sure to convert the column to str or
the output column will be Timestamp('1970-01-01 00:00:00.000002010')
dplyr_1.year = pd.to_datetime(dplyr_1.year)
dplyr_1.year[0]
Timestamp('2010-01-01 00:00:00')
So this is the Timestamp datatype.
If you want to check all dtypes and the output column:
dplyr_1.info()
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 12 entries, 0 to 11
Data columns (total 5 columns):
# Column Non-Null Count Dtype
--- ------ -------------- -----
0 year 12 non-null datetime64[ns]
1 dplyr 12 non-null int64
2 data.table 12 non-null int64
3 pandas 12 non-null int64
4 apache-spark 12 non-null int64
dtypes: datetime64[ns](1), int64(4)
memory usage: 608.0 bytes
dplyr_1.year
0 2010-01-01
1 2011-01-01
2 2012-01-01
3 2013-01-01
4 2014-01-01
5 2015-01-01
6 2016-01-01
7 2017-01-01
8 2018-01-01
9 2019-01-01
10 2020-01-01
11 2021-01-01
Name: year, dtype: datetime64[ns]