Calculate correlation between two sensors regarding the time
Your suggested method should work, assuming the two column are in the same dataframe with the same timestamps as the  index. This means that they are already aligned in time and therefore the time is implicitly encoded.

If there are any missing datapoints, you could impute them (fill them) with something like the previous value, which is usually best for time-series data. Replacing with e.g. the mean of the entire time-series might be misleading because there are temporal fluctuations/cycles involved.

df.fillna(method='ffill')


You could also simply plot them to see which kind of correlation value you might expect, doing something like this:

import matplotlib.pyplot as plt    # &lt;-- needed if running in script (not a Jupyter notebook)
df[["sensor1", "sensor2"]].plot()
plt.plot()