
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Convert String of Date into Time using Pandas
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]
Advertisements