Excel Python 自動化の超基本という本を購入してプログラムをダウンロードして動かしているのですがうまく動きません。
丸投げのような形ですいません。
原因が分かりません。ご教示をお願いします。
下記にプログラムとエラー内容を示します。
プログラム内容
#ケーキ店の売り上げのデータと気温を学習させる
import datetime
import pandas as pd
import matplotlib.pyplot as plt
from sklearn.linear_model import LinearRegression
def readTempData(fileName):#気象データを読み込み
df = pd.read_csv(fileName,encoding="Shift_JIS",skiprows=6)
df.columns = ["日付","気温","品質情報","均質番号"]
df['日付'] = pd.to_datetime(df['日付'])#曜日の列を追加 月曜日=0 日曜日=6
df["曜日"] = df["日付"].dt.dayofweek
df["月"] = df["日付"].dt.month
df["日"] = df["日付"].dt.day
return df
def readSalesData(fileName):#売上データを読み込み
df = pd.read_excel(fileName)
df['日付'] = pd.to_datetime(df['日付'])
return df
#気象データを読み込み
dfTemp = readTempData("気象データ2017.csv")
#売上データを読み込み
dfShop = readSalesData("洋菓子店売上リスト2017.xlsx") #気象データと売上データを統合
df = dfTemp.copy()
df = df.merge(dfShop,how="inner",on="日付")
x = df[["月","日","曜日","気温"]] #与えるデータ 2
y = df["売上金額"] #求めるデータ 23 print(x)
print(y)
#重回帰分析
model = LinearRegression()
model.fit(x,y) #訓練の開始
print(model.coef_) #回帰変数
print(model.intercept_) #切片
print(model.predict(x)) #予測値の表示
print(model.score(x,y)) #相関の表示
実行エラー内容
C:\Users\nao\AppData\Local\Programs\Python\Python35\python.exe "C:/Users/nao/Desktop/Excel×Python 自動化の超基本-20210523T192529Z-001/Excel×Python 自動化の超基本/Chapter8/pg35_01.py"
Traceback (most recent call last):
File "C:/Users/nao/Desktop/Excel×Python 自動化の超基本-20210523T192529Z-001/Excel×Python 自動化の超基本/Chapter8/pg35_01.py", line 20, in <module>
dfTemp = readTempData("気象データ2017.csv")
File "C:/Users/nao/Desktop/Excel×Python 自動化の超基本-20210523T192529Z-001/Excel×Python 自動化の超基本/Chapter8/pg35_01.py", line 7, in readTempData
df = pd.read_csv(fileName,encoding="Shift_JIS",skiprows=6)
File "C:\Users\nao\AppData\Roaming\Python\Python35\site-packages\pandas\io\parsers.py", line 678, in parser_f
return _read(filepath_or_buffer, kwds)
File "C:\Users\nao\AppData\Roaming\Python\Python35\site-packages\pandas\io\parsers.py", line 440, in _read
parser = TextFileReader(filepath_or_buffer, **kwds)
File "C:\Users\nao\AppData\Roaming\Python\Python35\site-packages\pandas\io\parsers.py", line 787, in init
self._make_engine(self.engine)
File "C:\Users\nao\AppData\Roaming\Python\Python35\site-packages\pandas\io\parsers.py", line 1014, in _make_engine
self._engine = CParserWrapper(self.f, **self.options)
File "C:\Users\nao\AppData\Roaming\Python\Python35\site-packages\pandas\io\parsers.py", line 1708, in init
self._reader = parsers.TextReader(src, **kwds)
File "pandas_libs\parsers.pyx", line 384, in pandas._libs.parsers.TextReader.cinit
File "pandas_libs\parsers.pyx", line 695, in pandas._libs.parsers.TextReader._setup_parser_source
FileNotFoundError: File b'\x8bC\x8f\xdb\x83f\x81[\x83^2017.csv' does not exist