Time Series Pandas Data Frame Function

It is useful to have a date time index when working with time series data. This function abstracts the process and lends itself to automation.

Before:

After:

Function Code:

import pandas as pd

def createTimeSeries(path, timeColumn, dateFormat):
    """
    This function takes a time string, converts it to a datetime stamp and sets it as the index
    
    :param path: string: path to .csv file 
    :param timeColumn: string: name of column to set as time index
    :param dateFormat: string: date format of the datetime index column
    :return: data frame: time indexed data frame
    """
    df = pd.read_csv(path)

    df.index = pd.to_datetime(df[timeColumn], format=dateFormat)

    df = df.drop(timeColumn, axis=1)

    return df


createTimeSeries(path, timeColumn, dateFormat)