How to convert Strings to DateTimes in Python?
DATA MUNGING DATA CLEANING PYTHON MACHINE LEARNING RECIPES PANDAS CHEATSHEET     ALL TAGS

How to convert Strings to DateTimes in Python?

How to convert Strings to DateTimes in Python?

This recipe helps you convert Strings to DateTimes in Python

0
In [1]:
## How to convert Strings to DateTimes in Python 
def Kickstarter_Example_49():
    print()
    print(format('How to convert Strings to DateTimes in Python',
                 '*^82'))
    import warnings
    warnings.filterwarnings("ignore")

    # Load libraries
    import numpy as np
    import pandas as pd

    # Create strings
    date_strings = np.array(['01-01-2015 11:35 PM',
                             '23-02-2016 12:01 AM',
                             '26-12-2017 09:09 PM'])
    print()
    print(date_strings)

    # Convert to datetimes
    print()
    print([pd.to_datetime(date,
                    format="%d-%m-%Y %I:%M %p",
                    errors="coerce") for date in date_strings])
Kickstarter_Example_49()
******************How to convert Strings to DateTimes in Python*******************

['01-01-2015 11:35 PM' '23-02-2016 12:01 AM' '26-12-2017 09:09 PM']

[Timestamp('2015-01-01 23:35:00'), Timestamp('2016-02-23 00:01:00'), Timestamp('2017-12-26 21:09:00')]

Relevant Projects

Data Science Project - Instacart Market Basket Analysis
Data Science Project - Build a recommendation engine which will predict the products to be purchased by an Instacart consumer again.

Build an Image Classifier for Plant Species Identification
In this machine learning project, we will use binary leaf images and extracted features, including shape, margin, and texture to accurately identify plant species using different benchmark classification techniques.

Forecast Inventory demand using historical sales data in R
In this machine learning project, you will develop a machine learning model to accurately forecast inventory demand based on historical sales data.

German Credit Dataset Analysis to Classify Loan Applications
In this data science project, you will work with German credit dataset using classification techniques like Decision Tree, Neural Networks etc to classify loan applications using R.

Zillow’s Home Value Prediction (Zestimate)
Data Science Project in R -Build a machine learning algorithm to predict the future sale prices of homes.

Choosing the right Time Series Forecasting Methods
There are different time series forecasting methods to forecast stock price, demand etc. In this machine learning project, you will learn to determine which forecasting method to be used when and how to apply with time series forecasting example.

PySpark Tutorial - Learn to use Apache Spark with Python
PySpark Project-Get a handle on using Python with Spark through this hands-on data processing spark python tutorial.

Time Series Forecasting with LSTM Neural Network Python
Deep Learning Project- Learn to apply deep learning paradigm to forecast univariate time series data.

Music Recommendation System Project using Python and R
Machine Learning Project - Work with KKBOX's Music Recommendation System dataset to build the best music recommendation engine.

Deep Learning with Keras in R to Predict Customer Churn
In this deep learning project, we will predict customer churn using Artificial Neural Networks and learn how to model an ANN in R with the keras deep learning package.