
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
Pandas program to convert a string of date into time
In this program, we will convert a date string like "24 August 2020" to 2020-08-24 00:00:00. We will use the to_datetime() function in pandas library to solve this task.
Algorithm
Step 1: Define a Pandas series containing date string. Step 2: Convert these date strings into date time format using the to_datetime format(). Step 3: Print the results.
Example Code
import pandas as pd series = pd.Series(["24 August 2020", "25 December 2020 20:05"]) print("Series: \n", series) datetime = pd.to_datetime(series) print("DateTime Format: \n", datetime)
Output
Series: 0 24 August 2020 1 25 December 2020 20:05 dtype: object DateTime Format: 0 2020-08-24 00:00:00 1 2020-12-25 20:05:00 dtype: datetime64[ns]
- Related Articles
- How to convert UTC date time into local date time using JavaScript?
- Java Program to convert a String to Date
- Java Program to convert Date into milliseconds
- Java Program to Convert String to Date
- How to convert a String into a Date object using JDBC API?
- How to convert a date to a string using the universal time convention?
- Golang Program to convert a string into Uppercase
- Golang Program to convert a string into lowercase
- Python program to convert a string into uppercase
- Python program to convert a string into lowercase
- How to convert date and time into int in Android sqlite?
- Python Pandas - Convert string data into datetime type
- How to Convert Number String to Date and Time in Excel?
- Java program to convert a list of characters into a string
- C# program to convert a list of characters into a string

Advertisements