0

I ran below code with jupyter notebook.

from pandas.plotting import scatter_matrix

df_NVDA['Returns'] = df_NVDA['Open'].pct_change(1)
df_NVDA['Returns'] = df_NVDA['Returns'].dropna()

df_AVGO['Returns'] = df_AVGO['Open'].pct_change(1)
df_AVGO['Returns'] = df_AVGO['Returns'].dropna()

df_PFE['Returns'] = df_PFE['Open'].pct_change(1)
df_PFE['Returns'] = df_PFE['Returns'].dropna()

NVDA_AVGO = pd.concat([df_NVDA['Returns'], df_AVGO['Returns']])
NVDA_AVGO.columns = ['NVIDIA', 'Broadcom',]


scatter_matrix(NVDA_AVGO, figsize=(12,10), alpha = 1.0, hist_kwds={'bin':40})

and it returns below error error Thanks for any answer. wish best for you.

I tried fix 'Series' object has no attribute 'columns' by below code

NVDA_AVGO_PFE = pd.concat([df_NVDA['Returns'], df_AVGO['Returns'], df_PFE['Returns']], axis=1)
NVDA_AVGO_PFE.columns = ['NVIDIA', 'Broadcom', 'Pfizer']

plt.figure(figsize=(12, 10))
scatter_matrix(NVDA_AVGO_PFE, alpha=1.0, hist_kwds={'bins': 40})

But it sill does not work. I think problem in.

scatter_matrix(NVDA_AVGO, figsize=(12,10), alpha = 1.0, hist_kwds={'bin':40})

1 Answers1

0

scatter_matrix expects a Dataframe object, but you passed it a Series object. You need to make sure NVDA_AVGO is a Dataframe, or to use another plotting function. Similiar Question here

IJokl
  • 56
  • 6
  • thanks guys! Do you rcm any way to make sure NVDA_AVGO is a Dataframe? Any df_xx['Return'] is Dataframe but I don't know how to make sure they are dataframe. – Minh Nguyễn Vũ Quang May 23 '23 at 11:35
  • You could use Python's `isinstance` or `type` to check if it is a `Dataframe`. [see this for more information](https://stackoverflow.com/a/14809149/14546262) – IJokl May 23 '23 at 11:46