Python — Time Series Data with Pandas

alpha2phi
The Startup
Published in
6 min readDec 1, 2020

--

Numeric, categorical and time series data are the types of data that we commonly dealt with as part of exploratory data analysis. In this article I will go through some basic operations with time series data.

The notebook for this article can be found here.

Generating Time Series Data

# Generate data with time
ts = pd.Series(np.random.rand(100), index=pd.date_range(datetime.now(), periods=100))
ts2020-11-30 08:53:58.271878 0.566087
2020-12-01 08:53:58.271878 0.906584
2020-12-02 08:53:58.271878 0.512919
2020-12-03 08:53:58.271878 0.878789
2020-12-04 08:53:58.271878 0.942902
...
2021-03-05 08:53:58.271878 0.983846
2021-03-06 08:53:58.271878 0.289516
2021-03-07 08:53:58.271878 0.840058
2021-03-08 08:53:58.271878 0.519680
2021-03-09 08:53:58.271878 0.506116
Freq: D, Length: 100, dtype: float64

To remove the time, set normalize to True.

# Generate data without time (normalize = True)
ts = pd.Series(np.random.rand(100), index=pd.date_range(datetime.now(), periods=100, normalize=True))
ts2020-11-30 0.403108
2020-12-01 0.386055
2020-12-02 0.904074
2020-12-03 0.705386
2020-12-04 0.527159
...
2021-03-05 0.271150
2021-03-06 0.851113
2021-03-07 0.778842
2021-03-08 0.380553
2021-03-09 0.552797
Freq: D, Length: 100, dtype

--

--

alpha2phi
The Startup

Software engineer, Data Science and ML practitioner.