以下のようなエラーが出てしまいます。
Traceback (most recent call last):
File " ", line 7, in <module>
df = pd.read_csv(u'日経平均_2014.csv', encoding='shift-jis')
AttributeError: module 'pandas' has no attribute 'read_csv'
以下コードになります。
import numpy as np
import pandas as pd
# [[短期, 長期], [短期, 長期] ・・・]
types = [[5, 25], [25, 75], [13, 26]]
df = pd.read_csv(u'日経平均_2014.csv', encoding='shift-jis')
df = df.sort_values(by=u'日付').reset_index(drop=True)
for short_day, long_day in types:
# 移動平均
rolling_s = df[u'終値'].rolling(short_day).mean().fillna(0)
rolling_l = df[u'終値'].rolling(long_day).mean().fillna(0)
# 移動平均のクロス確認
over_s_l = rolling_s > rolling_l
golden = (over_s_l != over_s_l.shift(1)) & (over_s_l == True)
dead = (over_s_l != over_s_l.shift(1)) & (over_s_l == False)
# 列 追加
# 0:クロスなし
# 1:ゴールデンクロス
# -1:デッドクロス
col_name = 'cross_' + str(short_day) + '_' + str(long_day)
df[col_name] = [x+y*-1 for x,y in zip(golden, dead)]
df[col_name] = np.append(np.array([0] * (long_day+1)), df[col_name][long_day+1:])
#