1 2 3 4 5 6 7 8 9 10 11 12 |
<span class="cm-keyword">import</span> <span class="cm-variable">numpy</span> <span class="cm-keyword">as</span> <span class="cm-variable">np</span> <span class="cm-keyword">from</span> <span class="cm-variable">numpy</span> <span class="cm-keyword">import</span> <span class="cm-variable">nan</span> <span class="cm-keyword">as</span> <span class="cm-variable">NA</span> <span class="cm-keyword">import</span> <span class="cm-variable">pandas</span> <span class="cm-keyword">as</span> <span class="cm-variable">pd</span> <span class="cm-variable">sample_data_frame</span> = <span class="cm-variable">pd</span>.<span class="cm-property">DataFrame</span>(<span class="cm-variable">np</span>.<span class="cm-property">random</span>.<span class="cm-property">rand</span>(<span class="cm-number">10</span>,<span class="cm-number">4</span>)) <span class="cm-comment">#一部のデータをわざと欠損</span> <span class="cm-variable">sample_data_frame</span>.<span class="cm-property">iloc</span>[<span class="cm-number">1</span>,<span class="cm-number">0</span>] = <span class="cm-variable">NA</span> <span class="cm-variable">sample_data_frame</span> |
dropnaを用いると、NaNのある行を全て取り除く
1 2 |
<span class="cm-variable">sample_data_frame</span>.<span class="cm-property">dropna</span>() |
ペアワイズ削除
1 2 3 |
<span class="cm-variable">sample_data_frame</span>[[<span class="cm-number">0</span>,<span class="cm-number">1</span>]].<span class="cm-property">dropna</span>() </code><code class="cm-s-ipython language-python"> |
1 |
1 |
コメントを残す