質問編集履歴
2
書式の改善
    
        title	
    CHANGED
    
    | 
         
            File without changes
         
     | 
    
        body	
    CHANGED
    
    | 
         @@ -32,6 +32,7 @@ 
     | 
|
| 
       32 
32 
     | 
    
         
             
                       #プロットの処理が続く
         
     | 
| 
       33 
33 
     | 
    
         | 
| 
       34 
34 
     | 
    
         
             
            ```
         
     | 
| 
      
 35 
     | 
    
         
            +
            エラー例①
         
     | 
| 
       35 
36 
     | 
    
         
             
            ```Python
         
     | 
| 
       36 
37 
     | 
    
         
             
             sheets = wb.sheets()
         
     | 
| 
       37 
38 
     | 
    
         
             
             month = np.array([sheets['Sheet1'].cell(row=i, column=0).value for i in range(1, 13)])
         
     | 
| 
         @@ -45,7 +46,7 @@ 
     | 
|
| 
       45 
46 
     | 
    
         
             
               # month行でエラー
         
     | 
| 
       46 
47 
     | 
    
         
             
            → TypeError: list indices must be integers or slices, not str
         
     | 
| 
       47 
48 
     | 
    
         
             
            ```
         
     | 
| 
       48 
     | 
    
         
            -
             
     | 
| 
      
 49 
     | 
    
         
            +
            エラー例②
         
     | 
| 
       49 
50 
     | 
    
         
             
            ```Python
         
     | 
| 
       50 
51 
     | 
    
         
             
             sheets = wb.sheets()
         
     | 
| 
       51 
52 
     | 
    
         
             
             month = np.array(sheets['Sheet1'].cell(row=i, column=0).value for i in range(1, 13))
         
     | 
1
numpy配列の初期化処理の前行追加
    
        title	
    CHANGED
    
    | 
         
            File without changes
         
     | 
    
        body	
    CHANGED
    
    | 
         @@ -16,6 +16,23 @@ 
     | 
|
| 
       16 
16 
     | 
    
         
             
            ④は完成イメージです。
         
     | 
| 
       17 
17 
     | 
    
         
             
            ### エラーメッセージ・該当のソースコード
         
     | 
| 
       18 
18 
     | 
    
         
             
            ```Python
         
     | 
| 
      
 19 
     | 
    
         
            +
             if request.method == 'POST':
         
     | 
| 
      
 20 
     | 
    
         
            +
               file = request.files['file']
         
     | 
| 
      
 21 
     | 
    
         
            +
               UPLOAD_FOLDER = r'C:\xxx\xxx\xxx\TestProject\uploads'
         
     | 
| 
      
 22 
     | 
    
         
            +
               app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER
         
     | 
| 
      
 23 
     | 
    
         
            +
                    if file:
         
     | 
| 
      
 24 
     | 
    
         
            +
                       filename = secure_filename(file.filename)
         
     | 
| 
      
 25 
     | 
    
         
            +
                       file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
         
     | 
| 
      
 26 
     | 
    
         
            +
                       wb = xlrd.open_workbook(r"C:\xxx\xxx\xxx\TestProject\uploads\test.xlsx")
         
     | 
| 
      
 27 
     | 
    
         
            +
                       sheets = wb.sheets()
         
     | 
| 
      
 28 
     | 
    
         
            +
                       month = np.array(sheets['Sheet1'].cell(row=i, column=0).value for i in range(1, 13))
         
     | 
| 
      
 29 
     | 
    
         
            +
                       sale = np.array(sheets['Sheet1'].cell(row=i, column=1).value for i in range(1, 13))
         
     | 
| 
      
 30 
     | 
    
         
            +
                       cost = np.array(sheets['Sheet1'].cell(row=i, column=2).value for i in range(1, 13))
         
     | 
| 
      
 31 
     | 
    
         
            +
                       benefit = sale - cost
         
     | 
| 
      
 32 
     | 
    
         
            +
                       #プロットの処理が続く
         
     | 
| 
      
 33 
     | 
    
         
            +
             
     | 
| 
      
 34 
     | 
    
         
            +
            ```
         
     | 
| 
      
 35 
     | 
    
         
            +
            ```Python
         
     | 
| 
       19 
36 
     | 
    
         
             
             sheets = wb.sheets()
         
     | 
| 
       20 
37 
     | 
    
         
             
             month = np.array([sheets['Sheet1'].cell(row=i, column=0).value for i in range(1, 13)])
         
     | 
| 
       21 
38 
     | 
    
         
             
             sale = np.array([sheets['Sheet1'].cell(row=i, column=1).value for i in range(1, 13)])
         
     | 
| 
         @@ -58,14 +75,8 @@ 
     | 
|
| 
       58 
75 
     | 
    
         
             
            plt.plot(w, z, label='benefit')
         
     | 
| 
       59 
76 
     | 
    
         
             
            ```
         
     | 
| 
       60 
77 
     | 
    
         | 
| 
       61 
     | 
    
         
            -
            numpy配列の初期化に問題があると考え、幾通りか試してみました。
         
     | 
| 
       62 
     | 
    
         
            -
            ```Python
         
     | 
| 
       63 
     | 
    
         
            -
            month = np.array([sheets['Sheet1'].cell(row=i, column=0).value for i in range(1, 13)])
         
     | 
| 
       64 
     | 
    
         
            -
            month = np.array(sheets['Sheet1'].cell(row=i, column=0).value for i in range(1, 13))
         
     | 
| 
       65 
     | 
    
         
            -
            month = np.array([sheets['Sheet1'].cell(row=i, column=0).value for i in range(1, sheets['Sheet1'].max_row)])
         
     | 
| 
       66 
     | 
    
         
            -
            month = np.array(sheets['Sheet1'].cell(row=i, column=0).value for i in range(1, sheets['Sheet1'].max_row))
         
     | 
| 
       67 
     | 
    
         
            -
            ```
         
     | 
| 
       68 
78 
     | 
    
         | 
| 
      
 79 
     | 
    
         
            +
             
     | 
| 
       69 
80 
     | 
    
         
             
            ### 環境
         
     | 
| 
       70 
81 
     | 
    
         | 
| 
       71 
82 
     | 
    
         
             
            開発環境:PyCharm
         
     |