0

I am trying to plot the ACF of the datasets but getting an error saying " AttributeError: 'DataFrame' object has no attribute 'market_value' ."

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import statsmodels.graphics.tsaplots as sgt
from statsmodels.tsa.arima_model import ARMA
from scipy.stats.distributions import chi2
import seaborn as sns 
sns.set()

df_comp = pd.read_csv("Index2018.csv")
df_comp.date = pd.to_datetime(df_comp.date,dayfirst = True) 
df_comp.set_index("date",inplace = True)
df_comp['market value'] = df_comp.ftse

size = int(len(df_comp)*0.8)
df, df_test = df_comp.iloc[:size],df_comp.iloc[size:]
sgt.plot_acf(df.market_value, zero = False, lags = 40) 
plt.title("PACF", size = 24)
plt.show()
  • Does this answer your question? [Data-frame Object has no Attribute](https://stackoverflow.com/questions/38134643/data-frame-object-has-no-attribute) – Derek O Jan 12 '22 at 03:24

2 Answers2

0

That column is "market value", note the space. Pandas lets you reference columns as dataframe attributes if the names are valid python variable names. Since there is a space, it can only be referenced by index. You could either name the column "market_value" or stick to using indexing df["market value"].

tdelaney
  • 63,514
  • 5
  • 71
  • 101
0

It is just because you have used the name incorrectly. You have used "df.market_value" in which "market_value" does not match the value which you have assigned earlier in df_comp['market value'] which is 'market value'.

instead of:

market_value in df.market_value

use:

['market value'] in df["market value"]

Akash Kumar
  • 128
  • 12