回答編集履歴

1

コード修正

2020/07/09 06:41

投稿

jeanbiego
jeanbiego

スコア3966

test CHANGED
@@ -12,7 +12,9 @@
12
12
 
13
13
  import numpy as np
14
14
 
15
+
16
+
15
- # ここからテスト用データ作成
17
+ # テスト用データ作成
16
18
 
17
19
  import io
18
20
 
@@ -74,15 +76,23 @@
74
76
 
75
77
  """
76
78
 
79
+
80
+
77
81
  # ここから処理
78
82
 
79
83
 
80
84
 
81
- def cal_vege(x, e, f_v):
85
+ def cal(x, e, f_v):
82
86
 
83
87
  #global e
84
88
 
89
+ if f_v == "Vege":
90
+
85
- names = ["Cucumber", "Carrot"]
91
+ names = ["Cucumber", "Carrot"]
92
+
93
+ else:
94
+
95
+ names = ["Grape", "Apple", "Orange"]
86
96
 
87
97
  sum_e = 0
88
98
 
@@ -104,19 +114,29 @@
104
114
 
105
115
  df[f"{f_v}_{e}"]=np.nan
106
116
 
107
- df[f"{f_v}_{e}"] = df.apply(cal_vege, e=e, f_v=f_v, axis=1)
117
+ df[f"{f_v}_{e}"] = df.apply(cal, e=e, f_v=f_v, axis=1)
108
118
 
109
119
  print(df)
110
120
 
111
121
  """
112
122
 
113
- Bascket Grape Apple Orange Cucumber Carrot Vege_Weight Vege_Price Vege_Suger_content Fruit_Weight Fruit_Price Fruit_Suger_content
123
+ Bascket Grape Apple Orange Cucumber Carrot Fruit_Weight Fruit_Price \
114
124
 
115
- 0 0 50 50 0 0 100 13.0 200.0 4.0 13.0 200.0 4.0
125
+ 0 0 50 50 0 0 100 15.0 350.0
116
126
 
117
- 1 1 0 20 80 50 50 9.0 125.0 2.5 9.0 125.0 2.5
127
+ 1 1 0 20 80 50 50 16.0 120.0
118
128
 
129
+ 2 2 0 70 30 70 30 18.5 170.0
130
+
131
+
132
+
133
+ Fruit_Suger_content Vege_Weight Vege_Price Vege_Suger_content
134
+
135
+ 0 4.0 13.0 200.0 4.0
136
+
137
+ 1 2.6 9.0 125.0 2.5
138
+
119
- 2 2 0 70 30 70 30 7.4 95.0 1.9 7.4 95.0 1.9
139
+ 2 4.1 7.4 95.0 1.9
120
140
 
121
141
  """
122
142