0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Jupyter Notebook: pandas.DataFrameから指定した列の値リストを抜き出したい

Posted at

次のようなテーブルデータを持ったpandasのDataFrameから、b列の値だけを抜き出す方法です。

a b
1 10
2 20
3 30

こういうリストがほしい: [10, 20, 30]

まず、DataFrameの定義:

df = pandas.DataFrame([
  {'a': 1, 'b': 10}, 
  {'a': 2, 'b': 20}, 
  {'a': 3, 'b': 30}
])

df[取り出したい列名]で指定する:

df['b']

なお、このときdf['b']のデータ型はpandas.core.series.Series型になる。

Jupyter Notebookでの実行例:

SlowTest.png
0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?