1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【図解・初心者向け】PandasのDataFrameとSeriesの違いをやさしく解説

Posted at

初心者向けに「DataFrameとSeriesの違い」を図解で解説!

Pythonのデータ分析ライブラリ「Pandas」を使い始めると最初に出会うのが「Series」と「DataFrame」ですが、この違いが直感的に理解しづらいという声をよく聞きます。

本記事では、図解・構造比較・コード実行結果を通じて、初心者でも理解しやすいようにまとめました。

DataFrameとSeriesの違い

以下は構造の違いを示した図です。

SeriesとDataFrameの構造の違い

構造 説明 次元
Series ラベル付きの1次元データ構造 1次元
DataFrame 行・列からなる2次元の表形式 2次元

コードで理解する違い

以下のコードは、SeriesとDataFrameの基本的な作成例です。

import pandas as pd

# Seriesの作成
s = pd.Series([10, 20, 30], name="A")

# DataFrameの作成
df = pd.DataFrame({"A": [10, 20, 30], "B": [40, 50, 60]})

出力結果:

Series(1次元):
0    10
1    20
2    30
Name: A, dtype: int64

DataFrame(2次元):
    A   B
0  10  40
1  20  50
2  30  60

よくある疑問:df["A"]とdf[["A"]]の違い

同じように見えるこの2つですが、結果の型と次元が異なります

記述 返り値の型 次元 特徴
df["A"] Series 1次元 1つの列をSeriesとして取得。構造が簡潔。
df[["A"]] DataFrame 2次元 1列でも表(DataFrame)として保持。後処理に便利。

出力の違いも確認してみましょう。

# Series(1次元)
print(df["A"])
0    10
1    20
2    30
Name: A, dtype: int64
# DataFrame(2次元)
print(df[["A"]])
    A
0  10
1  20
2  30

このように、見た目は似ていますが、データ構造・扱い方・後続処理への影響が異なります。初心者の方は特に混乱しやすいポイントです。

もっと詳しく学ぶには?

この記事の元記事では、さらに詳しく構造・使い方・操作例を解説しています。

✅ 図解・コード・出力結果付きで学べる元記事はこちら:
https://pythondatalab.com/pandas-dataframe-series/

関連ハッシュタグ

#Python #Pandas #データ分析 #初心者向け #DataFrame #Series

1
2
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
1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?