1 |
import pandas as pd |
Contents
■通常の辞書
1 2 3 |
<span class="cm-variable">fruits</span> = {<span class="cm-string">"banana"</span>: <span class="cm-number">3</span>, <span class="cm-string">"orange"</span>: <span class="cm-number">2</span>} <span class="cm-builtin">print</span>(<span class="cm-variable">pd</span>.<span class="cm-property">Series</span>(<span class="cm-variable">fruits</span>)) |
>>>
banana 3
orange 2
dtype: int64
banana 3
orange 2
dtype: int64
■辞書どうしの結合
1 2 3 4 |
<span role="presentation">index = ["cup", "chair", "table", "kagaku", "pictre"] data = [7012, 9406, 9609, 3824,9701] </span> |
1 |
<span role="presentation"><span class="cm-variable">series</span> = <span class="cm-variable">pd</span>.<span class="cm-property">Series</span>(<span class="cm-variable">data</span>, <span class="cm-variable">index</span>=<span class="cm-variable">index</span>)</span> |
1 |
<span role="presentation"></span>print(<span class="cm-variable">series</span>)>>> |
■条件抽出 フィルタリング
1 |
<span role="presentation"><span class="cm-comment"># series内の要素のうち、値が5以上10未満の要素を含むSeriesを作り、seriesに再代入</span></span> |
1 |
<span role="presentation"><span class="cm-variable">series</span> = <span class="cm-variable">series</span>[<span class="cm-variable">series</span> <span class="cm-operator">></span>= <span class="cm-number">5</span>][<span class="cm-variable">series</span> <span class="cm-operator"><</span> <span class="cm-number">10</span>]</span> |
1 |
<span role="presentation"></span><span role="presentation"><span class="cm-builtin">print</span><span class=" CodeMirror-matchingbracket">(</span><span class="cm-variable">series</span><span class=" CodeMirror-matchingbracket">)</span></span> |
コメントを残す