Sam Floral
Sam Floral

Reputation: 69

Time-series analysis with Python

So I have sensor-based time series data for a subject measured in second intervals, with the corresponding heart rate at each time point in an Excel format. My goal is to analyze whether there are any trends over time. When I import it into Python, I can see a certain number, but not the time. However, when imported in Excel, I can convert it into time format easily.

This is what it looks like in Python.. (column 1 = timestamp, column 2 = heart rate in bpm)

Example of the data in Excel, as seen in Python

This is what it should look like though:

enter image description here

This is what I tried to convert it into datetime format in Python:

import datetime
Time = datetime.datetime.now()
"%s:%s.%s" % (Time.minute, Time.second, str(Time.microsecond)[:2])
if isinstance(Time,datetime.datetime):
    print ("Yay!")

df3.set_index('Time', inplace=True)

Time gets recognized as a float64 if I do this, not datetime64 [ns].

Consequently, when I try to plot this timeseries, I get the following: Time series plot for heart rate

I even did the Dickey-fuller Test to analyze trends in Python with this dataset. Does my misconfiguration of the time column in Python actually affect my ADF-test? I'm assuming since only trends in the 'heartrate' column are analyzed with this code, it shouldn't matter, right?

Here's the code I used:

#Perform Dickey-Fuller test:
    print("Results of Dickey-Fuller Test:")
    dftest=adfuller(df3 ['HeartRate'], autolag='AIC')
    dfoutput=pd.Series(dftest[0:4], index=['Test Statistic','p-value','#Lags Used','Number of Observations Used'])
    for key,value in dftest[4].items():
        dfoutput['Critical Value (%s)'%key] = value
    print(dfoutput)

test_stationarity(df3)

Did I do this correctly? I don't have experience in the engineering field and I'm doing this to improve healthcare for older people, so any help will be very much appreciated!

Thanks in advance! :)

Upvotes: 0

Views: 490

Answers (1)

Carlos
Carlos

Reputation: 81

It seems that the dateformat in excel is expresed as the number of days that have passed since 12/30/1899. In order to transform the number on the timestamp column to seconds you only need to multiply it by 24*60*60 = 86400 (the number of seconds in one day).

Upvotes: 1

Related Questions