MACHINE LEARNING RECIPES
DATA CLEANING PYTHON
DATA MUNGING
PANDAS CHEATSHEET
ALL TAGS
# How to shift the time index of a time series using pandas functions?

# How to shift the time index of a time series using pandas functions?

This recipe helps you shift the time index of a time series using pandas functions

Suppose we have to shift index by desired number of periods with an optional time freq. It can be done by shift function.

So this recipe is a short example on How to shift the time index of a time series using pandas functions. Let's get started.

```
import pandas as pd
```

Let's pause and look at these imports. Pandas is generally used for performing mathematical operation and preferably over arrays.

```
df = pd.DataFrame({"Col1": [10, 20, 15, 30, 45],
"Col2": [13, 23, 18, 33, 48]},
index=pd.date_range("2020-01-01", "2020-01-05"))
print(df)
```

Here we have setup a random dataset with some random values in it.

```
print(df.shift(periods=3, fill_value=0))
```

Here we have shifted our time index by a period of 3 and all the remaining value have filled with 0.

Once we run the above code snippet, we will see:

Scroll down to the ipython file to look at the results.

We can see the time index being shifted by period of 3. For col1, 10 value is for 2020-01-04.

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

In this data science project, you will learn how to perform market basket analysis with the application of Apriori and FP growth algorithms based on the concept of association rule learning.

Deep Learning Project- Learn to apply deep learning paradigm to forecast univariate time series data.

In this machine learning pricing project, we implement a retail price optimization algorithm using regression trees. This is one of the first steps to building a dynamic pricing model.

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.

Machine Learning Project in R-Detect fraudulent click traffic for mobile app ads using R data science programming language.

In this data science project, you will predict borrowers chance of defaulting on credit loans by building a credit score prediction model.

In this project, we are going to work on Deep Learning using H2O to predict Census income.

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.

Data Science Project in R-Predict the sales for each department using historical markdown data from the Walmart dataset containing data of 45 Walmart stores.