Advertisement
Danila_lipatov

Correlation_function_python

Nov 3rd, 2023 (edited)
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.93 KB | None | 0 0
  1. import pandas as pd
  2. import matplotlib.pyplot as plt
  3. import numpy as np
  4. import scipy.stats
  5. from statsmodels.graphics.tsaplots import plot_acf
  6. import scipy
  7. import spectrochempy as scp
  8. #https://scicoding.com/4-ways-of-calculating-autocorrelation-in-python/
  9. if __name__ == '__main__':
  10.     df = pd.read_csv('CompanyABCProfit.csv').set_index('Year')
  11.     fig = plt.figure(figsize=(10, 10))
  12.     plt.xlabel('Year')
  13.     plt.ylabel('Profit')
  14.     # df.plot()
  15.     # plt.close()
  16.     values_df = []
  17.     for value in df["Profit(Rs '000)"]:
  18.         values_df.append(value)
  19.     corr_func = (np.correlate(values_df - df.mean()[0], values_df - df.mean()[0], 'full')) / df.var()[0] / len(values_df)
  20.     fig = plt.figure(figsize=(10, 10))
  21.     corr_function = pd.DataFrame(corr_func).reset_index()
  22.     corr_function['index'] = corr_function['index'] - len(df)
  23.     corr_function = corr_function.set_index('index')
  24.     corr_function.plot()
  25.     plt.show()
  26.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement