How to Convert Integer to Datetime in Pandas DataFrame? Last Updated : 03 Oct, 2022 Summarize Comments Improve Suggest changes Share Like Article Like Report Let's discuss how to convert an Integer to Datetime in it. Now to convert Integers to Datetime in Pandas DataFrame. Syntax of pd.to_datetimedf['DataFrame Column'] = pd.to_datetime(df['DataFrame Column'], format=specify your format)Create the DataFrame to Convert Integer to Datetime in Pandas Check data type for the 'Dates' column is Integer. Python # importing pandas package import pandas as pd # creating a dataframe values = {'Dates': [20190902, 20190913, 20190921], 'Attendance': ['Attended', 'Not Attended', 'Attended'] } df = pd.DataFrame(values, columns=['Dates', 'Attendance']) # display print(df) print(df.dtypes) Output: Example 1: Now to convert it into Datetime we use the previously mentioned syntax. Since in this example the date format is yyyymmdd, the date format can be represented as follows: format= '%Y%m%d' Python3 # importing pandas package import pandas as pd # creating the dataframe values = {'Dates': [20190902, 20190913, 20190921], 'Attendance': ['Attended', 'Not Attended', 'Attended'] } df = pd.DataFrame(values, columns=['Dates', 'Attendance']) # converting the integers to datetime format df['Dates'] = pd.to_datetime(df['Dates'], format='%Y%m%d') # display print(df) print(df.dtypes) Output: Example 2: Now, suppose the Pandas DataFrame has a date in the format yymmdd. In this case, the date format would now contain 'y' in lowercase: format='%y%m%d' Python3 # importing pandas package import pandas as pd # creating dataframe values = {'Dates': [190902, 190913, 190921], 'Attendance': ['Attended', 'Not Attended', 'Attended'] } df = pd.DataFrame(values, columns=['Dates', 'Attendance']) # changing the integer dates to datetime format df['Dates'] = pd.to_datetime(df['Dates'], format='%y%m%d') # display print(df) print(df.dtypes) Output: Example 3: Now, let's suppose that your integers contain both date and time. In that case, the format that you should specify is: format='%Y%m%d%H%M%S' Python3 # importing pandas package import pandas as pd # creating dataframe values = {'Dates': [20190902093000, 20190913093000, 20190921200000], 'Attendance': ['Attended', 'Not Attended', 'Attended'] } df = pd.DataFrame(values, columns=['Dates', 'Attendance']) # changing integer values to datetime format df['Dates'] = pd.to_datetime(df['Dates'], format='%Y%m%d%H%M%S') # display print(df) print(df.dtypes) Output: Example 4: Consider this DataFrame with microseconds in our DateTime values. In this case, the format should be specified as: format='%Y%m%d%H%M%S%F' Python3 # importing pandas package import pandas as pd # creating dataframe values = {'Dates': [20190902093000912, 20190913093000444, 20190921200000009], 'Attendance': ['Attended', 'Not Attended', 'Attended'] } df = pd.DataFrame(values, columns=['Dates', 'Attendance']) # changing the integer dates to datetime format df['Dates'] = pd.to_datetime(df['Dates'], format='%Y%m%d%H%M%S%F') # display print(df) print(df.dtypes) Output: Comment More infoAdvertise with us Next Article How to Convert String to Integer in Pandas DataFrame? A annie_saxena Follow Improve Article Tags : Python Python-pandas Python pandas-dataFrame Practice Tags : python Similar Reads How to Convert Float to Datetime in Pandas DataFrame? Pandas Dataframe provides the freedom to change the data type of column values. We can change them from Integers to Float type, Integer to Datetime, String to Integer, Float to Datetime, etc. For converting float to DateTime we use pandas.to_datetime() function and following syntax is used : Syntax: 3 min read How to Convert Datetime to Date in Pandas ? DateTime is a collection of dates and times in the format of "yyyy-mm-dd HH:MM:SS" where yyyy-mm-dd is referred to as the date and HH:MM:SS is referred to as Time. In this article, we are going to discuss converting DateTime to date in pandas. For that, we will extract the only date from DateTime us 4 min read How to Convert String to Integer in Pandas DataFrame? Let's see methods to convert string to an integer in Pandas DataFrame: Method 1: Use of Series.astype() method. Syntax: Series.astype(dtype, copy=True, errors=âraiseâ) Parameters: This method will take following parameters: dtype: Data type to convert the series into. (for example str, float, int).c 3 min read How to Convert Integers to Strings in Pandas DataFrame? In this article, we'll look at different methods to convert an integer into a string in a Pandas dataframe. In Pandas, there are different functions that we can use to achieve this task : map(str)astype(str)apply(str)applymap(str) Example 1 : In this example, we'll convert each value of a column of 3 min read How to convert DateTime to integer in Python Python provides a module called DateTime to perform all the operations related to date and time. It has a rich set of functions used to perform almost all the operations that deal with time. It needs to be imported first to use the functions and it comes along with python, so no need to install it s 2 min read Convert Floats to Integers in a Pandas DataFrame Let us see how to convert float to integer in a Pandas DataFrame. We will be using the astype() method to do this. It can also be done using the apply() method. Convert Floats to Integers in a Pandas DataFrameBelow are the ways by which we can convert floats to integers in a Pandas DataFrame: Using 3 min read Like