How to generate timeseries using Pandas and Seaborn?

This recipe helps you generate timeseries using Pandas and Seaborn

Recipe Objective

Have you ever worked on time series data, a dataset in which targets depends on the time and data. For this you have to convert the data set into time series dataset.

This data science python source code does the following:
1.Creating your own pandas series and timestams them.
2. Visualizes the series using seaborn libraries

So this is the recipe on we can generate timeseries using Pandas and Seaborn.

Get Access to Time Series Analysis Real World Projects in Python

Step 1 - Import the library

import pandas as pd import matplotlib.pyplot as plt import seaborn as sns

We have imported pandas, seaborn and matplotlib.pyplot which is needed.

Step 2 - Setting up the Data

We have created a dictionary of data and passed it in pd.DataFrame to make a dataframe. In the dictionary we have many features named 'date', 'regiment_1', 'regiment_2', etc. We have set index as date and rest other as features. data = {'date': ['2014-05-01 18:47:05.069722', '2014-05-01 18:47:05.119994', '2014-05-02 18:47:05.178768', '2014-05-02 18:47:05.230071', '2014-05-02 18:47:05.230071', '2014-05-02 18:47:05.280592', '2014-05-04 18:47:05.436523', '2014-05-04 18:47:05.486877'], 'regiment_1': [14, 26, 25, 14, 31, 25, 62, 41], 'regiment_2': [52, 66, 78, 15, 25, 25, 86, 1], 'regiment_3': [13, 26, 25, 62, 24, 14, 15, 15], 'regiment_4': [44, 15, 15, 14, 54, 25, 24, 72], 'regiment_5': [25, 24, 5, 25, 25, 27, 62, 5], 'regiment_6': [14, 15, 15, 14, 26, 25, 62, 24], 'regiment_7': [46, 57, 26, 15, 26, 25, 62, 41]} df = pd.DataFrame(data, columns = ['date', 'regiment_1', 'regiment_2', 'regiment_3', 'regiment_4', 'regiment_5', 'regiment_6', 'regiment_7']) df = df.set_index(df.date) print(); print(df)

Step 3 - Making Time Series

We have passed features from sns.tsplot to make time series plot of different features with index as date. sns.tsplot([df.regiment_1, df.regiment_2, df.regiment_3, df.regiment_4, df.regiment_5, df.regiment_6, df.regiment_7]) plt.show() So the output comes as

                                                  date  regiment_1  \
date                                                                 
2014-05-01 18:47:05.069722  2014-05-01 18:47:05.069722          14   
2014-05-01 18:47:05.119994  2014-05-01 18:47:05.119994          26   
2014-05-02 18:47:05.178768  2014-05-02 18:47:05.178768          25   
2014-05-02 18:47:05.230071  2014-05-02 18:47:05.230071          14   
2014-05-02 18:47:05.230071  2014-05-02 18:47:05.230071          31   
2014-05-02 18:47:05.280592  2014-05-02 18:47:05.280592          25   
2014-05-04 18:47:05.436523  2014-05-04 18:47:05.436523          62   
2014-05-04 18:47:05.486877  2014-05-04 18:47:05.486877          41   

                            regiment_2  regiment_3  regiment_4  regiment_5  \
date                                                                         
2014-05-01 18:47:05.069722          52          13          44          25   
2014-05-01 18:47:05.119994          66          26          15          24   
2014-05-02 18:47:05.178768          78          25          15           5   
2014-05-02 18:47:05.230071          15          62          14          25   
2014-05-02 18:47:05.230071          25          24          54          25   
2014-05-02 18:47:05.280592          25          14          25          27   
2014-05-04 18:47:05.436523          86          15          24          62   
2014-05-04 18:47:05.486877           1          15          72           5   

                            regiment_6  regiment_7  
date                                                
2014-05-01 18:47:05.069722          14          46  
2014-05-01 18:47:05.119994          15          57  
2014-05-02 18:47:05.178768          15          26  
2014-05-02 18:47:05.230071          14          15  
2014-05-02 18:47:05.230071          26          26  
2014-05-02 18:47:05.280592          25          25  
2014-05-04 18:47:05.436523          62          62  
2014-05-04 18:47:05.486877          24          41  

Download Materials

What Users are saying..

profile image

Ed Godalle

Director Data Analytics at EY / EY Tech
linkedin profile url

I am the Director of Data Analytics with over 10+ years of IT experience. I have a background in SQL, Python, and Big Data working with Accenture, IBM, and Infosys. I am looking to enhance my skills... Read More

Relevant Projects

MLOps using Azure Devops to Deploy a Classification Model
In this MLOps Azure project, you will learn how to deploy a classification machine learning model to predict the customer's license status on Azure through scalable CI/CD ML pipelines.

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.

Build a Multi Touch Attribution Machine Learning Model in Python
Identifying the ROI on marketing campaigns is an essential KPI for any business. In this ML project, you will learn to build a Multi Touch Attribution Model in Python to identify the ROI of various marketing efforts and their impact on conversions or sales..

PyTorch Project to Build a LSTM Text Classification Model
In this PyTorch Project you will learn how to build an LSTM Text Classification model for Classifying the Reviews of an App .

Recommender System Machine Learning Project for Beginners-1
Recommender System Machine Learning Project for Beginners - Learn how to design, implement and train a rule-based recommender system in Python

Mastering A/B Testing: A Practical Guide for Production
In this A/B Testing for Machine Learning Project, you will gain hands-on experience in conducting A/B tests, analyzing statistical significance, and understanding the challenges of building a solution for A/B testing in a production environment.

Avocado Machine Learning Project Python for Price Prediction
In this ML Project, you will use the Avocado dataset to build a machine learning model to predict the average price of avocado which is continuous in nature based on region and varieties of avocado.

Census Income Data Set Project-Predict Adult Census Income
Use the Adult Income dataset to predict whether income exceeds 50K yr based oncensus data.

Build Real Estate Price Prediction Model with NLP and FastAPI
In this Real Estate Price Prediction Project, you will learn to build a real estate price prediction machine learning model and deploy it on Heroku using FastAPI Framework.

Learn How to Build a Logistic Regression Model in PyTorch
In this Machine Learning Project, you will learn how to build a simple logistic regression model in PyTorch for customer churn prediction.