Я запускаю приведенный ниже код и получаю сообщение об ошибке:

'Series' object has no attribute 'columns'

Вот код.

from pandas_datareader import data 
import matplotlib.pyplot as plt
import pandas as pd
import datetime
import numpy as np
from pandas_datareader import data as wb
#import plotly.graph_objects as go

companies = {
    'Amazon':'AMZN',
    'Apple':'AAPL',
    'Walgreen':'WBA',
    'Northrop Grumman':'NOC',
    'Boeing':'BA',
    'Lockheed Martin':'LMT',
    'McDonalds':'MCD',
    'Intel':'INTC',
    'Navistar':'NAV',
    'IBM':'IBM',
    'Texas Instruments':'TXN',
    'MasterCard':'MA',
    'Microsoft':'MSFT',
    'General Electrics':'GE',
    'Symantec':'SYMC',
    'American Express':'AXP',
    'Pepsi':'PEP',
    'Coca Cola':'KO',
    'Johnson & Johnson':'JNJ',
    'Toyota':'TM',
    'Honda':'HMC',
    'Mistubishi':'MSBHY',
    'Sony':'SNE',
    'Exxon':'XOM',
    'Chevron':'CVX',
    'Valero Energy':'VLO',
    'Ford':'F',
    'Bank of America':'BAC'}

start = '2019-4-30'
end = '2019-10-31'
# N = 90
# start = datetime.now() - timedelta(days=N)
# end = dt.datetime.today()


price_data = []
for ticker in tickers:
    prices = wb.DataReader(list(companies_dict.values()), start = start, end = end, data_source='yahoo')[['Open', 'Adj Close']]
    price_data.append(prices.assign(ticker=ticker)[['ticker', 'Open', 'Adj Close']])

df = pd.concat(price_data)
df.dtypes
df.head()
df.shape


#################
pd.set_option('display.max_columns', 500)

df = df.reset_index()
df = df.set_index('Date')
table = df.pivot(columns='ticker')
# By specifying col[1] in below list comprehension
# You can select the stock names under multi-level column
table.columns = [col[1] for col in table.columns]
table.head()


##################

stock_open = np.array(df['Open']).T # stock_open is numpy array of transpose of df['Open']
stock_close = np.array(df['Adj Close']).T # stock_close is numpy array of transpose of df['Close']


movements = (stock_close - stock_open)
sum_of_movement = np.sum(movements)


for i in range(len(companies)):
    print('companies:{}, Change:{}'.format(df['Adj Close'].columns[i],sum_of_movement[i]))


# Import the necessary packages
from sklearn.pipeline import make_pipeline
from sklearn.preprocessing import Normalizer
from sklearn.cluster import KMeans# Define a normalizer
normalizer = Normalizer()# Create Kmeans model
kmeans = KMeans(n_clusters = 10,max_iter = 1000)# Make a pipeline chaining normalizer and kmeans
pipeline = make_pipeline(normalizer,kmeans)# Fit pipeline to daily stock movements
pipeline.fit(movements)
labels = pipeline.predict(movements)

# The companies and their cluster number is printed.
df1 = pd.DataFrame({'labels':labels,'companies':list(companies)}).sort_values(by=['labels'],axis = 0))

Я следую примеру по ссылке ниже.

https://medium.com/datadriveninvestor/stock-market-clustering-with-k-means-clustering-in-python-4bf6bd5bd685

-2
ASH