1 |
<span role="presentation"><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> |
1 |
<span role="presentation"></span> |
1 |
<span role="presentation"><span class="cm-variable">index</span> = [<span class="cm-string">"apple"</span>, <span class="cm-string">"orange"</span>, <span class="cm-string">"banana"</span>, <span class="cm-string">"strawberry"</span>, <span class="cm-string">"kiwifruit"</span>]</span> |
1 |
<span role="presentation"><span class="cm-variable">data</span> = [<span class="cm-number">10</span>, <span class="cm-number">5</span>, <span class="cm-number">8</span>, <span class="cm-number">12</span>, <span class="cm-number">3</span>]</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> |
1 |
<span role="presentation"><span class="cm-comment"># valuesにseriesのデータを代入</span></span> |
1 |
<span role="presentation"><span class="cm-variable">values</span>= <span class="cm-variable">series</span>.<span class="cm-property">values</span></span> |
1 2 3 |
<span role="presentation">結果 [10 5 8 12 3] </span> |
1 |
<span role="presentation"><span class="cm-comment"># indexにseriesのインデックスを代入してください</span></span> |
1 |
<span role="presentation"><span class="cm-variable">index</span> =<span class="cm-variable">series</span>.<span class="cm-property">index</span></span> |
Index([‘apple’, ‘orange’, ‘banana’, ‘strawberry’, ‘kiwifruit’], dtype=’object’)
コメントを残す