質問編集履歴

1

データソースの追記、実行コードの修正、出力の修正

2022/09/23 13:31

投稿

h_r_k
h_r_k

score1

test CHANGED
File without changes
test CHANGED
@@ -9,10 +9,222 @@
9
9
  ### 知りたいこと
10
10
  ・pandas.Dataframe.mean()の結果で「nan」もしくは「0.0」が出力される理由と正しい結果を取得する方法
11
11
 
12
+ ### データ
13
+ データセット Kaggle - American Express - Default Prediction
14
+ https://www.kaggle.com/datasets/munumbutt/amexfeather
15
+
12
- ### 具体的なコードと出力結果
16
+ ### 実行したコード
17
+ ```python
18
+ ## データの読み込み
19
+ for data in ["test", "train"]:
20
+ df = pd.read_feather(f'../input/amexfeather/{data}_data.ftr')
21
+ df = df.groupby('customer_ID').tail(1).set_index('customer_ID')
22
+ if data == "test":
23
+ df_test = df
24
+ else:
25
+ df_train = df
26
+
27
+ del df
28
+ gc.collect()
29
+
30
+ categorical = ['B_30', 'B_38', 'D_114', 'D_116', 'D_117', 'D_120', 'D_126', 'D_63', 'D_64', 'D_66', 'D_68']
31
+
32
+ df_train.drop(categorical, axis="columns", inplace=True)
33
+ df_test.drop(categorical, axis="columns", inplace=True)
34
+
35
+ ## 問題発生部分
36
+ df_train.mean()
37
+
38
+ ```
39
+
40
+ ### 出力結果
41
+
42
+ ```python
43
+
44
+ df_train.mean()
45
+
46
+ P_2 NaN
47
+ D_39 NaN
48
+ B_1 0.000000
49
+ B_2 NaN
50
+ R_1 0.000000
51
+ S_3 NaN
52
+ D_41 0.000000
53
+ B_3 NaN
54
+ D_42 0.177979
55
+ D_43 0.000000
56
+ D_44 0.000000
57
+ B_4 NaN
58
+ D_45 NaN
59
+ B_5 0.000000
60
+ R_2 0.000000
61
+ D_46 NaN
62
+ D_47 NaN
63
+ D_48 NaN
64
+ D_49 0.191162
65
+ B_6 NaN
66
+ B_7 NaN
67
+ B_8 NaN
68
+ D_50 0.000000
69
+ D_51 NaN
70
+ B_9 NaN
71
+ R_3 0.000000
72
+ D_52 NaN
73
+ P_3 NaN
74
+ B_10 NaN
75
+ D_53 0.000000
76
+ S_5 0.000000
77
+ B_11 0.000000
78
+ S_6 NaN
79
+ D_54 NaN
80
+ R_4 0.000000
81
+ S_7 NaN
82
+ B_12 0.000000
83
+ S_8 NaN
84
+ D_55 NaN
85
+ D_56 0.000000
86
+ B_13 0.000000
87
+ R_5 0.000000
88
+ D_58 NaN
89
+ S_9 0.000000
90
+ B_14 0.000000
91
+ D_59 NaN
92
+ D_60 NaN
93
+ D_61 NaN
94
+ B_15 0.000000
95
+ S_11 NaN
96
+ D_62 NaN
97
+ D_65 0.000000
98
+ B_16 NaN
99
+ B_17 NaN
100
+ B_18 NaN
101
+ B_19 NaN
102
+ B_20 NaN
103
+ S_12 NaN
104
+ R_6 0.000000
105
+ S_13 NaN
106
+ B_21 0.000000
107
+ D_69 NaN
108
+ B_22 0.000000
109
+ D_70 0.000000
110
+ D_71 0.000000
111
+ D_72 0.000000
112
+ S_15 NaN
113
+ B_23 NaN
114
+ D_73 0.170654
115
+ P_4 0.000000
116
+ D_74 NaN
117
+ D_75 NaN
118
+ D_76 0.143066
119
+ B_24 0.000000
120
+ R_7 NaN
121
+ D_77 0.000000
122
+ B_25 0.000000
123
+ B_26 0.000000
124
+ D_78 0.000000
125
+ D_79 0.000000
126
+ R_8 0.000000
127
+ R_9 0.252930
128
+ S_16 0.000000
129
+ D_80 0.000000
130
+ R_10 0.000000
131
+ R_11 0.000000
132
+ B_27 0.000000
133
+ D_81 0.000000
134
+ D_82 0.000000
135
+ S_17 0.000000
136
+ R_12 NaN
137
+ B_28 NaN
138
+ R_13 0.000000
139
+ D_83 0.000000
140
+ R_14 NaN
141
+ R_15 0.000000
142
+ D_84 0.000000
143
+ R_16 0.000000
144
+ B_29 0.046021
145
+ S_18 0.000000
146
+ D_86 0.000000
147
+ D_87 1.000000
148
+ R_17 0.000000
149
+ R_18 0.000000
150
+ D_88 0.208130
151
+ B_31 NaN
152
+ S_19 0.000000
153
+ R_19 0.000000
154
+ B_32 0.000000
155
+ S_20 0.000000
156
+ R_20 0.000000
157
+ R_21 0.000000
158
+ B_33 NaN
159
+ D_89 0.000000
160
+ R_22 0.000000
161
+ R_23 0.000000
162
+ D_91 0.000000
163
+ D_92 0.000000
164
+ D_93 0.000000
165
+ D_94 0.000000
166
+ R_24 0.000000
167
+ R_25 0.000000
168
+ D_96 0.000000
169
+ S_22 NaN
170
+ S_23 NaN
171
+ S_24 NaN
172
+ S_25 NaN
173
+ S_26 0.000000
174
+ D_102 NaN
175
+ D_103 NaN
176
+ D_104 NaN
177
+ D_105 NaN
178
+ D_106 0.222290
179
+ D_107 NaN
180
+ B_36 0.000000
181
+ B_37 0.000000
182
+ R_26 0.087769
183
+ R_27 NaN
184
+ D_108 0.072083
185
+ D_109 0.000000
186
+ D_110 0.746582
187
+ D_111 0.886230
188
+ B_39 0.320068
189
+ D_112 NaN
190
+ B_40 NaN
191
+ S_27 NaN
192
+ D_113 NaN
193
+ D_115 NaN
194
+ D_118 NaN
195
+ D_119 NaN
196
+ D_121 NaN
197
+ D_122 NaN
198
+ D_123 0.000000
199
+ D_124 NaN
200
+ D_125 0.000000
201
+ D_127 0.000000
202
+ D_128 NaN
203
+ D_129 NaN
204
+ B_41 0.000000
205
+ B_42 0.110535
206
+ D_130 NaN
207
+ D_131 0.000000
208
+ D_132 0.209473
209
+ D_133 0.000000
210
+ R_28 0.000000
211
+ D_134 0.341553
212
+ D_135 0.029068
213
+ D_136 0.246826
214
+ D_137 0.014122
215
+ D_138 0.158936
216
+ D_139 NaN
217
+ D_140 0.000000
218
+ D_141 NaN
219
+ D_142 0.000000
220
+ D_143 NaN
221
+ D_144 0.000000
222
+ D_145 0.000000
223
+ target 0.258934
224
+ dtype: float64
225
+
226
+ ```
13
- ![イメージ説明](https://ddjkaamml8q8x.cloudfront.net/questions/2022-09-23/3ef4a61c-b079-4ab2-9d02-9e3e9907584a.png)
227
+ ![イメージ説明](https://ddjkaamml8q8x.cloudfront.net/questions/2022-09-23/1a6b6f67-2d3f-4473-a556-dd62639a05d4.png)
14
-
15
- ![イメージ説明](https://ddjkaamml8q8x.cloudfront.net/questions/2022-09-23/e30c7961-0bcd-4e0f-b9ff-957caad0b780.png)
16
228
 
17
229
 
18
230
  ### 試したこと