• Skip to main content
  • Skip to primary sidebar

学習記録

Seriesで辞書の値や要素を取り出す

2017年11月25日 by 河副 太智 Leave a Comment

文字と数字を組み合わせた辞書の作成が可能

 

index = [“cup”, “chair”, “table”, “kagaku”, “pictre”]
data = [7012, 9406, 9609, 3824,9701]

# indexとdataを含むSeriesを作成しseriesに代入
series = pd.Series(data,index=index)

1
2
3
4
5
6
cup       7012
chair     9406
table     9609
kagaku    3824
pictre    9701
dtype: int64

1
<span role="presentation">​</span>

1
<span role="presentation"><span class="cm-comment"># インデックス参照を用いてseriesの2つ目から4つ目までの3つの要素を取り出してitems1に代入</span></span>

1
2
3
4
5
6
7
8
<span role="presentation"><span class="cm-variable">items1</span> = <span class="cm-variable">series</span>[<span class="cm-number">1</span>:<span class="cm-number">4</span>]
 
結果
 
orange 5
</span>banana 8
strawberry 12
dtype: int64

1
<span role="presentation">​</span>

1
2
3
<span role="presentation"><span class="cm-comment"># インデックス値を指定する方法を用いて"apple", "banana", "kiwifruit"のインデックスと持つ要素を取り出してitems2に代入
 
</span></span><span role="presentation"><span class="cm-variable">items2</span>=<span class="cm-variable">series</span>[[<span class="cm-string">"apple"</span>,<span class="cm-string">"banana"</span>,<span class="cm-string">"kiwifruit"</span>]]</span>

1
<span role="presentation">​</span>

1
結果

1
2
3
4
apple        10
banana        8
kiwifruit     3
dtype: int64
このエントリーをはてなブックマークに追加

Tweet
[`yahoo` not found]
このエントリーを Google ブックマーク に追加
LinkedIn にシェア
LINEで送る


Filed Under: Pandas

Reader Interactions

コメントを残す コメントをキャンセル

メールアドレスが公開されることはありません。 ※ が付いている欄は必須項目です

Primary Sidebar

カテゴリー

  • AWS
  • Bootstrap
  • Dash
  • Django
  • flask
  • GIT(sourcetree)
  • Plotly/Dash
  • VPS
  • その他tool
  • ブログ
  • プログラミング
    • Bokeh
    • css
    • HoloViews
    • Jupyter
    • Numpy
    • Pandas
    • PosgreSQL
    • Python 基本
    • python3
      • webアプリ
    • python3解説
    • scikit-learn
    • scipy
    • vps
    • Wordpress
    • グラフ
    • コマンド
    • スクレイピング
    • チートシート
    • データクレンジング
    • ブロックチェーン
    • 作成実績
    • 時系列分析
    • 機械学習
      • 分析手法
      • 教師有り
    • 異常値検知
    • 自然言語処理
  • 一太郎
  • 数学
    • sympy
      • 対数関数(log)
      • 累乗根(n乗根)
    • 暗号学

Copyright © 2025 · Genesis Sample on Genesis Framework · WordPress · Log in