How to generate timeseries using Pandas and Seaborn?
0

How to generate timeseries using Pandas and Seaborn?

This recipe helps you generate timeseries using Pandas and Seaborn
In [2]:
## How to generate timeseries using Pandas and Seaborn
def Snippet_115():
    print()
    print(format('How to generate timeseries using Pandas and Seaborn','*^82'))

    import warnings
    warnings.filterwarnings("ignore")

    # load libraries
    import pandas as pd
    import matplotlib.pyplot as plt
    import seaborn as sns

    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-03 18:47:05.332662', '2014-05-03 18:47:05.385109',
                     '2014-05-04 18:47:05.436523', '2014-05-04 18:47:05.486877'],
        'deaths_regiment_1': [34, 43, 14, 15, 15, 14, 31, 25, 62, 41],
        'deaths_regiment_2': [52, 66, 78, 15, 15, 5, 25, 25, 86, 1],
        'deaths_regiment_3': [13, 73, 82, 58, 52, 87, 26, 5, 56, 75],
        'deaths_regiment_4': [44, 75, 26, 15, 15, 14, 54, 25, 24, 72],
        'deaths_regiment_5': [25, 24, 25, 15, 57, 68, 21, 27, 62, 5],
        'deaths_regiment_6': [84, 84, 26, 15, 15, 14, 26, 25, 62, 24],
        'deaths_regiment_7': [46, 57, 26, 15, 15, 14, 26, 25, 62, 41]}

    df = pd.DataFrame(data, columns = ['date', 'battle_deaths', 'deaths_regiment_1',
                'deaths_regiment_2', 'deaths_regiment_3', 'deaths_regiment_4',
                'deaths_regiment_5', 'deaths_regiment_6', 'deaths_regiment_7'])
    df = df.set_index(df.date)

    # dataFrame
    print(); print(df)

    # Time Series Plot
    sns.tsplot([df.deaths_regiment_1, df.deaths_regiment_2, df.deaths_regiment_3, df.deaths_regiment_4,
                df.deaths_regiment_5, df.deaths_regiment_6, df.deaths_regiment_7])
    plt.show()

Snippet_115()
***************How to generate timeseries using Pandas and Seaborn****************

                                                  date battle_deaths  \
date
2014-05-01 18:47:05.069722  2014-05-01 18:47:05.069722           NaN
2014-05-01 18:47:05.119994  2014-05-01 18:47:05.119994           NaN
2014-05-02 18:47:05.178768  2014-05-02 18:47:05.178768           NaN
2014-05-02 18:47:05.230071  2014-05-02 18:47:05.230071           NaN
2014-05-02 18:47:05.230071  2014-05-02 18:47:05.230071           NaN
2014-05-02 18:47:05.280592  2014-05-02 18:47:05.280592           NaN
2014-05-03 18:47:05.332662  2014-05-03 18:47:05.332662           NaN
2014-05-03 18:47:05.385109  2014-05-03 18:47:05.385109           NaN
2014-05-04 18:47:05.436523  2014-05-04 18:47:05.436523           NaN
2014-05-04 18:47:05.486877  2014-05-04 18:47:05.486877           NaN

                            deaths_regiment_1  deaths_regiment_2  \
date
2014-05-01 18:47:05.069722                 34                 52
2014-05-01 18:47:05.119994                 43                 66
2014-05-02 18:47:05.178768                 14                 78
2014-05-02 18:47:05.230071                 15                 15
2014-05-02 18:47:05.230071                 15                 15
2014-05-02 18:47:05.280592                 14                  5
2014-05-03 18:47:05.332662                 31                 25
2014-05-03 18:47:05.385109                 25                 25
2014-05-04 18:47:05.436523                 62                 86
2014-05-04 18:47:05.486877                 41                  1

                            deaths_regiment_3  deaths_regiment_4  \
date
2014-05-01 18:47:05.069722                 13                 44
2014-05-01 18:47:05.119994                 73                 75
2014-05-02 18:47:05.178768                 82                 26
2014-05-02 18:47:05.230071                 58                 15
2014-05-02 18:47:05.230071                 52                 15
2014-05-02 18:47:05.280592                 87                 14
2014-05-03 18:47:05.332662                 26                 54
2014-05-03 18:47:05.385109                  5                 25
2014-05-04 18:47:05.436523                 56                 24
2014-05-04 18:47:05.486877                 75                 72

                            deaths_regiment_5  deaths_regiment_6  \
date
2014-05-01 18:47:05.069722                 25                 84
2014-05-01 18:47:05.119994                 24                 84
2014-05-02 18:47:05.178768                 25                 26
2014-05-02 18:47:05.230071                 15                 15
2014-05-02 18:47:05.230071                 57                 15
2014-05-02 18:47:05.280592                 68                 14
2014-05-03 18:47:05.332662                 21                 26
2014-05-03 18:47:05.385109                 27                 25
2014-05-04 18:47:05.436523                 62                 62
2014-05-04 18:47:05.486877                  5                 24

                            deaths_regiment_7
date
2014-05-01 18:47:05.069722                 46
2014-05-01 18:47:05.119994                 57
2014-05-02 18:47:05.178768                 26
2014-05-02 18:47:05.230071                 15
2014-05-02 18:47:05.230071                 15
2014-05-02 18:47:05.280592                 14
2014-05-03 18:47:05.332662                 26
2014-05-03 18:47:05.385109                 25
2014-05-04 18:47:05.436523                 62
2014-05-04 18:47:05.486877                 41
In [ ]: