Note

Pandas (32) 본문

Pandas

Pandas (32)

알 수 없는 사용자 2022. 8. 24. 23:04
728x90

How to compute the autocorrelations of a numeric series?

# Input
ser = pd.Series(np.arange(20) + np.random.normal(1, 10, 20))

# Solution
autocorrelations = [ser.autocorr(i).round(2) for i in range(11)]
print(autocorrelations[1:])
print('Lag having highest correlation: ', np.argmax(np.abs(autocorrelations[1:]))+1)

# output
[0.29999999999999999, -0.11, -0.17000000000000001, 0.46000000000000002, 0.28000000000000003, -0.040000000000000001, -0.37, 0.41999999999999998, 0.47999999999999998, 0.17999999999999999]
Lag having highest correlation:  9

'Pandas' 카테고리의 다른 글

Pandas (34)  (0) 2022.08.26
Pandas (33)  (0) 2022.08.25
Pandas (31)  (0) 2022.08.23
Pandas (30)  (0) 2022.08.22
Pandas (29)  (0) 2022.08.21
Comments