How to convert string variables into DateTime variables in Python?
DATA MUNGING

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

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

Data Science Project in Python on BigMart Sales Prediction
The goal of this data science project is to build a predictive model and find out the sales of each product at a given Big Mart store.

Mercari Price Suggestion Challenge Data Science Project
Data Science Project in Python- Build a machine learning algorithm that automatically suggests the right product prices.

Predict Macro Economic Trends using Kaggle Financial Dataset
In this machine learning project, you will uncover the predictive value in an uncertain world by using various artificial intelligence, machine learning, advanced regression and feature transformation techniques.

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.

Ecommerce product reviews - Pairwise ranking and sentiment analysis
This project analyzes a dataset containing ecommerce product reviews. The goal is to use machine learning models to perform sentiment analysis on product reviews and rank them based on relevance. Reviews play a key role in product recommendation systems.

Loan Eligibility Prediction using Gradient Boosting Classifier
This data science in python project predicts if a loan should be given to an applicant or not. We predict if the customer is eligible for loan based on several factors like credit score and past history.

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.

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.

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.