How to convert string variables into DateTime variables in Python?
DATA MUNGING DATA CLEANING PYTHON MACHINE LEARNING RECIPES PANDAS CHEATSHEET     ALL TAGS

How to convert string variables into DateTime variables in Python?

How to convert string variables into DateTime variables in Python?

This recipe helps you convert string variables into DateTime variables in Python

0
In [1]:
## How to convert string variables into DateTime variables in Python
def Kickstarter_Example_79():
    print()
    print(format('How to convert string variables into DateTime variables in Python','*^82'))

    import warnings
    warnings.filterwarnings("ignore")

    # load libraries
    import pandas as pd

    # Create a dataset with the index being a set of names
    raw_data = {'date': ['2017-09-01T01:23:41.004053', '2017-10-15T01:21:38.004053',
                         '2017-12-17T01:17:38.004053'],
                'score': [25, 94, 57]}
    df = pd.DataFrame(raw_data, columns = ['date', 'score'])
    print(); print(df); print(df.dtypes)

    # convert strings to DateTime
    df["date"] = pd.to_datetime(df["date"])
    print(); print(df); print(df.dtypes)

Kickstarter_Example_79()
********How to convert string variables into DateTime variables in Python*********

                         date  score
0  2017-09-01T01:23:41.004053     25
1  2017-10-15T01:21:38.004053     94
2  2017-12-17T01:17:38.004053     57
date     object
score     int64
dtype: object

                        date  score
0 2017-09-01 01:23:41.004053     25
1 2017-10-15 01:21:38.004053     94
2 2017-12-17 01:17:38.004053     57
date     datetime64[ns]
score             int64
dtype: object

Relevant Projects

Perform Time series modelling using Facebook Prophet
In this project, we are going to talk about Time Series Forecasting to predict the electricity requirement for a particular house using Prophet.

Identifying Product Bundles from Sales Data Using R Language
In this data science project in R, we are going to talk about subjective segmentation which is a clustering technique to find out product bundles in sales data.

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.

Data Science Project on Wine Quality Prediction in R
In this R data science project, we will explore wine dataset to assess red wine quality. The objective of this data science project is to explore which chemical properties will influence the quality of red wines.

Solving Multiple Classification use cases Using H2O
In this project, we are going to talk about H2O and functionality in terms of building Machine Learning models.

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.

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.

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.

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

Ensemble Machine Learning Project - All State Insurance Claims Severity Prediction
In this ensemble machine learning project, we will predict what kind of claims an insurance company will get. This is implemented in python using ensemble machine learning algorithms.