<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Pandas基礎入門｜SeriesとDataFrameの基本構造と作り方を徹底解説 | Python Data Lab（Pythonデータラボ）</title>
	<atom:link href="https://pythondatalab.com/category/pandas/basic/feed/" rel="self" type="application/rss+xml" />
	<link>https://pythondatalab.com</link>
	<description>Python初心者向けに、わかりやすいデータ分析の解説を提供します。</description>
	<lastBuildDate>Wed, 10 Jun 2026 17:04:42 +0000</lastBuildDate>
	<language>ja</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.0</generator>

<image>
	<url>https://pythondatalab.com/wp-content/uploads/2025/12/cropped-rogo-32x32.png</url>
	<title>Pandas基礎入門｜SeriesとDataFrameの基本構造と作り方を徹底解説 | Python Data Lab（Pythonデータラボ）</title>
	<link>https://pythondatalab.com</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>pandas value_counts()の使い方｜件数集計・割合表示・欠損値の数え方を解説</title>
		<link>https://pythondatalab.com/pandas-value-counts/</link>
					<comments>https://pythondatalab.com/pandas-value-counts/#respond</comments>
		
		<dc:creator><![CDATA[coin_collector]]></dc:creator>
		<pubDate>Sun, 22 Mar 2026 11:07:30 +0000</pubDate>
				<category><![CDATA[基礎]]></category>
		<guid isPermaLink="false">https://pythondatalab.com/?p=1780</guid>

					<description><![CDATA[<p>pandasのvalue_counts()の使い方を初心者向けに解説。件数集計、割合表示（normalize=True）、欠損値の数え方（dropna=False）、並び替え、表記ゆれの確認、groupby().size()やcount()との違いまで実例付きでわかりやすく紹介します。</p>
<p>&lt;p&gt;The post <a rel="nofollow" href="https://pythondatalab.com/pandas-value-counts/">pandas value_counts()の使い方｜件数集計・割合表示・欠損値の数え方を解説</a> first appeared on <a rel="nofollow" href="https://pythondatalab.com">Python Data Lab（Pythonデータラボ）</a>.&lt;/p&gt;</p>
]]></description>
										<content:encoded><![CDATA[
<div class="colab-article">

<!-- ▼▼▼ Pandasシリーズナビ（開始） ▼▼▼ -->
<div id="pandas-series-nav" class="pdl-series-nav" style="clear: both; overflow: auto; position: relative; width: 100%; max-width: 100%; box-sizing: border-box; border: 2px solid #4db6ac; background: #eafaf8; padding: 14px 18px; border-radius: 10px; margin: 1.5em 0; box-shadow: 0 3px 6px rgba(0,0,0,0.05); transition: box-shadow .3s ease;">
<p style="margin: 0 0 6px 0; font-weight: 600; color: #00695c; font-size: 1.05em;">💡 Pandas DataFrame入門シリーズ</p>
<p>このページは「<a style="color: #00796b; text-decoration: underline; font-weight: 500;" href="https://pythondatalab.com/pandas-dataframe/">Pandas DataFrame入門</a>」シリーズの一部です。データの作成から結合・集計までを体系的に学べます。</p>
</div>
<!-- ▲▲▲ Pandasシリーズナビ（終了） ▲▲▲ -->




  <div id="toc" class="toc tnt-number toc-center tnt-number border-element"><input type="checkbox" class="toc-checkbox" id="toc-checkbox-1" checked><label class="toc-title" for="toc-checkbox-1">目次</label>
    <div class="toc-content">
    <ol class="toc-list open"><li><a href="#toc1" tabindex="0">こんなことで困っていませんか？</a></li><li><a href="#toc2" tabindex="0">この記事でわかること</a></li><li><a href="#toc3" tabindex="0">value_counts() とは？</a></li><li><a href="#toc4" tabindex="0">サンプルデータの作成</a></li><li><a href="#toc5" tabindex="0">基本の使い方｜件数を数える</a></li><li><a href="#toc6" tabindex="0">割合を表示する方法｜normalize=True</a></li><li><a href="#toc7" tabindex="0">パーセント表示にする方法</a></li><li><a href="#toc8" tabindex="0">欠損値も数える方法｜dropna=False</a></li><li><a href="#toc9" tabindex="0">欠損値を含めた割合を表示する方法</a></li><li><a href="#toc10" tabindex="0">少ない順に並べたいとき｜ascending=True</a></li><li><a href="#toc11" tabindex="0">値順に並べたいとき｜sort_index()</a></li><li><a href="#toc12" tabindex="0">よく使う書き方まとめ【比較表】</a></li><li><a href="#toc13" tabindex="0">value_counts() の結果を表として扱う方法</a></li><li><a href="#toc14" tabindex="0">件数と割合をまとめて表示する方法</a></li><li><a href="#toc15" tabindex="0">value_counts() は表記ゆれの発見にも便利</a></li><li><a href="#toc16" tabindex="0">数値データにも使える</a></li><li><a href="#toc17" tabindex="0">value_counts() の結果はグラフ化にも使える</a></li><li><a href="#toc18" tabindex="0">value_counts() と groupby().size() と count() の違い</a><ol><li><a href="#toc19" tabindex="0">どう使い分ければよいか</a></li><li><a href="#toc20" tabindex="0">初心者向けの覚え方</a></li></ol></li><li><a href="#toc21" tabindex="0">よくある使い方の例</a></li><li><a href="#toc22" tabindex="0">大規模データでの考慮事項</a></li><li><a href="#toc23" tabindex="0">よくある間違い</a><ol><li><a href="#toc24" tabindex="0">NaN が表示されないのはおかしいと思ってしまう</a></li><li><a href="#toc25" tabindex="0">割合が 0〜1 の小数で返ってきて戸惑う</a></li><li><a href="#toc26" tabindex="0">表記ゆれに気づかず、そのまま集計してしまう</a></li></ol></li><li><a href="#toc27" tabindex="0">ワンポイント</a></li><li><a href="#toc28" tabindex="0">まとめ</a><ol><li><a href="#toc29" tabindex="0">関連記事</a></li><li><a href="#toc30" tabindex="0">value_counts() とは何ですか？</a></li><li><a href="#toc31" tabindex="0">割合を表示するにはどうすればよいですか？</a></li><li><a href="#toc32" tabindex="0">欠損値も数えられますか？</a></li><li><a href="#toc33" tabindex="0">groupby().size() との違いは何ですか？</a></li></ol></li></ol>
    </div>
  </div>

<h2><span id="toc1">こんなことで困っていませんか？</span></h2>
<p>Pandasでデータ分析をしていると、次のような場面によく出会います。</p>
<ul>
<li>列の中に同じ値が何件あるか知りたい</li>
<li>件数だけでなく割合も見たい</li>
<li>欠損値（NaN）が何件あるか確認したい</li>
<li>groupby() と何が違うのかわからない</li>
<li>表記ゆれや入力ミスをすばやく見つけたい</li>
</ul>
<p>そんなときに便利なのが、value_counts() です。</p>
<p>value_counts() は、<strong>1列の中にある値ごとの出現回数を集計するためのメソッド</strong>です。Pandasでデータを読み込んだあとに、まず中身をざっくり把握したいときによく使います。</p>
<p>さらに、normalize=True を使えば割合も確認でき、dropna=False を使えば欠損値も含めて数えられます。そのため、単なる件数集計だけでなく、<strong>カテゴリの偏り確認、欠損値チェック、表記ゆれの発見</strong>にも役立ちます。</p>
<p>この記事では、Pandas初心者向けに value_counts() の基本から、割合表示、欠損値の数え方、表記ゆれの見つけ方、groupby().size() や count() との違いまで、実例つきでわかりやすく解説します。</p>

<p>▶️ value_countsの公式ドキュメントも参考にしてください：<br /><a rel="noopener" href="https://pandas.pydata.org/docs/reference/api/pandas.Series.value_counts.html" target="_blank">pandas.Series.value_counts Documentation</a></p>

<h2><span id="toc2">この記事でわかること</span></h2>
<ul>
<li>value_counts() の基本的な使い方がわかる</li>
<li>値ごとの<strong>件数</strong>を集計できる</li>
<li>値ごとの<strong>割合</strong>を表示できる</li>
<li><strong>欠損値（NaN）を含めて</strong>数えられる</li>
<li>表記ゆれやカテゴリの偏りを見つけられる</li>
<li>groupby().size() や count() との違いがわかる</li>
</ul>

<h2><span id="toc3">value_counts() とは？</span></h2>
<p>value_counts() は、<strong>Seriesの中にある値ごとの出現回数を数えるメソッド</strong>です。</p>
<p>たとえば、会員ランクの列があるときに value_counts() を使うと、Gold が何件、Silver が何件、Bronze が何件あるかをすぐに集計できます。</p>
<p>基本構文は次のとおりです。</p>
<p>df[&#8220;列名&#8221;].value_counts()
まずは、<strong>「1列の値の出現回数を数える」</strong>と覚えておけば大丈夫です。</p>

<h2><span id="toc4">サンプルデータの作成</span></h2>
<p>今回は、少し実務に近いサンプルデータを使って説明します。</p>

<pre class="language-python"><code class="language-python">import pandas as pd
import numpy as np

df = pd.DataFrame({
    &quot;member_rank&quot;: [&quot;Gold&quot;, &quot;Silver&quot;, &quot;Gold&quot;, &quot;Bronze&quot;, np.nan, &quot;Silver&quot;, &quot;Gold&quot;, &quot;bronze&quot;, &quot; Silver &quot;],
    &quot;city&quot;: [&quot;Tokyo&quot;, &quot;Osaka&quot;, &quot;Tokyo&quot;, &quot;Nagoya&quot;, &quot;Tokyo&quot;, &quot;osaka&quot;, &quot;Tokyo &quot;, &quot;Nagoya&quot;, np.nan],
    &quot;rating&quot;: [5, 4, 5, 3, 4, 4, 5, 3, 4]
})

print(df)</code></pre>
<div class="table-scroll"><figure class="wp-block-table"><table class="wp-block-table"><thead><tr><th>member_rank</th><th>city</th><th>rating</th></tr></thead><tbody><tr><td>Gold</td><td>Tokyo</td><td>5</td></tr><tr><td>Silver</td><td>Osaka</td><td>4</td></tr><tr><td>Gold</td><td>Tokyo</td><td>5</td></tr><tr><td>Bronze</td><td>Nagoya</td><td>3</td></tr><tr><td>NaN</td><td>Tokyo</td><td>4</td></tr><tr><td>Silver</td><td>osaka</td><td>4</td></tr><tr><td>Gold</td><td>Tokyo</td><td>5</td></tr><tr><td>bronze</td><td>Nagoya</td><td>3</td></tr><tr><td>Silver</td><td>NaN</td><td>4</td></tr></tbody></table></figure></div>
<p>このデータからわかること</p>
<p>このデータには、member_rank のようなカテゴリ列、city のような文字列列、rating のような数値列が含まれています。さらに、NaN、大文字・小文字の違い、余分な空白も入っているため、value_counts() の基本だけでなく、実務でよくある問題も確認できます。</p>
<p>つまり、この1つのサンプルで、基本の件数集計、割合表示、欠損値の確認、表記ゆれの発見、数値データへの応用まで自然に学べるようになっています。</p>

<h2><span id="toc5">基本の使い方｜件数を数える</span></h2>
<p>まずは、もっとも基本的な使い方です。</p>

<pre class="language-python"><code class="language-python">print(df[&quot;member_rank&quot;].value_counts())</code></pre>
<div class="table-scroll"><figure class="wp-block-table"><table class="wp-block-table"><thead><tr><th>member_rank</th><th>count</th></tr></thead><tbody><tr><td>Gold</td><td>3</td></tr><tr><td>Silver</td><td>2</td></tr><tr><td>Bronze</td><td>1</td></tr><tr><td>bronze</td><td>1</td></tr><tr><td> Silver</td><td>1</td></tr></tbody></table></figure></div>
<p><strong>この結果からわかること</strong></p>
<p>この結果を見ると、Gold が3件で最も多く、次に Silver が2件あることがわかります。</p>
<p>一方で、Bronze と bronze、Silver と &#8221; Silver &#8221; が別々に集計されています。これは、value_counts() が<strong>見た目ではなく、実際の値をそのまま集計する</strong>ためです。大文字・小文字の違いや前後の空白があると、別の値として数えられます。</p>
<p>また、この結果には NaN が表示されていません。これは、value_counts() がデフォルトでは欠損値を除外するためです。</p>
<p><strong>ポイント</strong></p>
<p>value_counts() は、<strong>件数の多い順</strong>に並びます
デフォルトでは NaN は数えません
空白や大文字・小文字の違いも、<strong>別の値として集計されます</strong></p>

<h2><span id="toc6">割合を表示する方法｜normalize=True</span></h2>
<p>件数だけでなく、全体に対する割合を見たいこともあります。その場合は normalize=True を指定します。</p>

<pre class="language-python"><code class="language-python">print(df[&quot;member_rank&quot;].value_counts(normalize=True))</code></pre>
<div class="table-scroll"><figure class="wp-block-table"><table class="wp-block-table"><thead><tr><th>member_rank</th><th>proportion</th></tr></thead><tbody><tr><td>Gold</td><td>0.375</td></tr><tr><td>Silver</td><td>0.250</td></tr><tr><td>Bronze</td><td>0.125</td></tr><tr><td>bronze</td><td>0.125</td></tr><tr><td> Silver</td><td>0.125</td></tr></tbody></table></figure></div>
<p><strong>この結果からわかること</strong></p>
<p>この結果では、Gold が全体の 37.5%、Silver が 25.0% を占めていることがわかります。</p>
<p>件数だけを見ると「Gold は3件」としかわかりませんが、割合を見ることで、<strong>全体の中でどれくらいの比率なのか</strong>を把握できます。</p>
<p>特に、データ件数が増えると、単純な件数だけでは比較しにくくなることがあります。そのため、カテゴリの偏りを確認したいときは、件数と割合の両方を見るのがおすすめです。</p>
<p><strong>ポイント</strong></p>
<p>0〜1 の小数で返ります
0.375 は <strong>37.5% を意味します
件数よりも、</strong>全体に対する比率を比較しやすくなります
見やすくしたい場合は round() を組み合わせます。</p>

<pre class="language-python"><code class="language-python">print(df[&quot;member_rank&quot;].value_counts(normalize=True).round(3))</code></pre>
<div class="table-scroll"><figure class="wp-block-table"><table class="wp-block-table"><thead><tr><th>member_rank</th><th>proportion</th></tr></thead><tbody><tr><td>Gold</td><td>0.375</td></tr><tr><td>Silver</td><td>0.250</td></tr><tr><td>Bronze</td><td>0.125</td></tr><tr><td>bronze</td><td>0.125</td></tr><tr><td> Silver</td><td>0.125</td></tr></tbody></table></figure></div>
<h2><span id="toc7">パーセント表示にする方法</span></h2>
<p>割合をパーセントで表示したい場合は、100をかけます。</p>

<pre class="language-python"><code class="language-python">print((df[&quot;member_rank&quot;].value_counts(normalize=True) * 100).round(1))</code></pre>
<div class="table-scroll"><figure class="wp-block-table"><table class="wp-block-table"><thead><tr><th>member_rank</th><th>proportion</th></tr></thead><tbody><tr><td>Gold</td><td>37.5</td></tr><tr><td>Silver</td><td>25.0</td></tr><tr><td>Bronze</td><td>12.5</td></tr><tr><td>bronze</td><td>12.5</td></tr><tr><td> Silver</td><td>12.5</td></tr></tbody></table></figure></div>
<p>% をつけて表示したい場合は、次のように書けます。</p>

<pre class="language-python"><code class="language-python">rate = (df[&quot;member_rank&quot;].value_counts(normalize=True) * 100).round(1).astype(str) + &quot;%&quot;
print(rate)</code></pre>
<div class="table-scroll"><figure class="wp-block-table"><table class="wp-block-table"><thead><tr><th>member_rank</th><th>proportion</th></tr></thead><tbody><tr><td>Gold</td><td>37.5%</td></tr><tr><td>Silver</td><td>25.0%</td></tr><tr><td>Bronze</td><td>12.5%</td></tr><tr><td>bronze</td><td>12.5%</td></tr><tr><td> Silver</td><td>12.5%</td></tr></tbody></table></figure></div>
<p>この結果からわかること</p>
<p>割合をパーセントで表示すると、結果がかなり直感的になります。特に、レポートやブログ記事など、人に見せる前提の場面では 0.375 より 37.5% のほうが伝わりやすいです。</p>
<p>分析途中では小数のままでも問題ありませんが、<strong>説明用の資料ではパーセント表示のほうが親切</strong>です。</p>

<h2><span id="toc8">欠損値も数える方法｜dropna=False</span></h2>
<p>value_counts() は、デフォルトでは <strong>NaN を集計しません</strong>。</p>
<p>NaN も含めて数えたい場合は、dropna=False を指定します。</p>

<pre class="language-python"><code class="language-python">print(df[&quot;member_rank&quot;].value_counts(dropna=False))</code></pre>
<div class="table-scroll"><figure class="wp-block-table"><table class="wp-block-table"><thead><tr><th>member_rank</th><th>count</th></tr></thead><tbody><tr><td>Gold</td><td>3</td></tr><tr><td>Silver</td><td>2</td></tr><tr><td>Bronze</td><td>1</td></tr><tr><td>NaN</td><td>1</td></tr><tr><td>bronze</td><td>1</td></tr><tr><td> Silver</td><td>1</td></tr></tbody></table></figure></div>
<p>この結果からわかること</p>
<p>今度は NaN が1件あることが表示されました。つまり、この member_rank 列には欠損値が1つ含まれていると確認できます。</p>
<p>基本の value_counts() だけを見ると、欠損値が存在しないように見えることがあります。ですが、dropna=False を使えば、<strong>欠損値も含めた本当の分布</strong>を見ることができます。</p>
<p><strong>ポイント</strong></p>
<ul>
<li>dropna=False をつけると、欠損値も件数に含まれます</li>
<li>データ品質の確認に便利です</li>
<li>前処理の前に、欠損値の有無をざっくり把握できます</li>
</ul>

<h2><span id="toc9">欠損値を含めた割合を表示する方法</span></h2>
<p>NaN も含めて割合を出したい場合は、normalize=True と dropna=False を組み合わせます。</p>

<pre class="language-python"><code class="language-python">print(df[&quot;member_rank&quot;].value_counts(normalize=True, dropna=False).round(3))</code></pre>
<div class="table-scroll"><figure class="wp-block-table"><table class="wp-block-table"><thead><tr><th>member_rank</th><th>proportion</th></tr></thead><tbody><tr><td>Gold</td><td>0.333</td></tr><tr><td>Silver</td><td>0.222</td></tr><tr><td>Bronze</td><td>0.111</td></tr><tr><td>NaN</td><td>0.111</td></tr><tr><td>bronze</td><td>0.111</td></tr><tr><td> Silver</td><td>0.111</td></tr></tbody></table></figure></div>
<p><strong>この結果からわかること</strong></p>
<p>この結果では、NaN が全体の約11.1%を占めていることがわかります。件数だけでなく割合でも確認できるため、<strong>欠損値の影響がどれくらい大きいか</strong>を判断しやすくなります。</p>
<p>たとえば、欠損値が1件だけなら大きな問題でないこともありますが、全体の3割、4割を占めるようなら、分析結果への影響は無視できません。割合で見ると、その重要度をより判断しやすくなります。</p>

<h2><span id="toc10">少ない順に並べたいとき｜ascending=True</span></h2>
<p>value_counts() はデフォルトで件数の多い順に並びます。少ない順にしたい場合は ascending=True を使います。</p>

<pre class="language-python"><code class="language-python">print(df[&quot;member_rank&quot;].value_counts(dropna=False, ascending=True))</code></pre>
<div class="table-scroll"><figure class="wp-block-table"><table class="wp-block-table"><thead><tr><th>member_rank</th><th>count</th></tr></thead><tbody><tr><td>NaN</td><td>1</td></tr><tr><td>Bronze</td><td>1</td></tr><tr><td> Silver</td><td>1</td></tr><tr><td>bronze</td><td>1</td></tr><tr><td>Silver</td><td>2</td></tr><tr><td>Gold</td><td>3</td></tr></tbody></table></figure></div>
<p><strong>この結果からわかること</strong></p>
<p>少ない順に並べると、件数の少ないカテゴリから確認できます。この例では、NaN、Bronze、bronze、&#8221; Silver &#8221; がいずれも1件ずつであることがすぐにわかります。</p>
<p>多数派だけでなく、<strong>少数派や例外的な値を見つけたいとき</strong>に便利です。入力ミスや珍しいカテゴリを探したいときは、降順より昇順のほうが見やすい場合があります。</p>

<h2><span id="toc11">値順に並べたいとき｜sort_index()</span></h2>
<p>value_counts() は件数順に並びます。値そのものの順番で見たいときは、sort_index() を組み合わせます。</p>

<pre class="language-python"><code class="language-python">print(df[&quot;member_rank&quot;].value_counts(dropna=False).sort_index())</code></pre>
<div class="table-scroll"><figure class="wp-block-table"><table class="wp-block-table"><thead><tr><th>member_rank</th><th>count</th></tr></thead><tbody><tr><td> Silver</td><td>1</td></tr><tr><td>Bronze</td><td>1</td></tr><tr><td>Gold</td><td>3</td></tr><tr><td>Silver</td><td>2</td></tr><tr><td>bronze</td><td>1</td></tr><tr><td>NaN</td><td>1</td></tr></tbody></table></figure></div>
<p>この結果からわかること</p>
<p>件数順ではなく、値そのものの順番で並べたいときに便利です。ただし、空白つきの &#8221; Silver &#8221; が先頭に来ていることからもわかるように、<strong>余分な空白があると並び順にも影響する</strong>ことがあります。</p>
<p>ここでも、表記ゆれや前処理の重要性が見えてきます。</p>

<h2><span id="toc12">よく使う書き方まとめ【比較表】</span></h2>
<div class="table-scroll"><figure class="wp-block-table"><table class="wp-block-table"><thead><tr><th>やりたいこと</th><th>書き方</th></tr></thead><tbody><tr><td>件数を数える</td><td>df[&#8220;列名&#8221;].value_counts()</td></tr><tr><td>割合を出す</td><td>df[&#8220;列名&#8221;].value_counts(normalize=True)</td></tr><tr><td>欠損値も含める</td><td>df[&#8220;列名&#8221;].value_counts(dropna=False)</td></tr><tr><td>欠損値込みで割合を出す</td><td>df[&#8220;列名&#8221;].value_counts(normalize=True, dropna=False)</td></tr><tr><td>少ない順に並べる</td><td>df[&#8220;列名&#8221;].value_counts(ascending=True)</td></tr><tr><td>値順に並べる</td><td>df[&#8220;列名&#8221;].value_counts().sort_index()</td></tr><tr><td>件数でソートしない</td><td>df[&#8220;列名&#8221;].value_counts(sort=False)</td></tr></tbody></table></figure></div>
この表の見方

<p>まずは次の3つを押さえておくと十分です。</p>
<ul>
<li>件数を数える</li>
<li>割合を出す</li>
<li>欠損値も含める</li>
</ul>
<p>そのうえで、並び順を変えたいときに ascending=True や sort_index() を使う、と覚えると整理しやすいです。
また、デフォルトの件数ソートが不要な場合は <code>sort=False</code> を使うこともできます。</p>

<h2><span id="toc13">value_counts() の結果を表として扱う方法</span></h2>
<p>value_counts() の結果は Series です。そのため、そのままでも使えますが、表として扱いやすくしたい場合は reset_index() を使います。</p>

<pre class="language-python"><code class="language-python">result = df[&quot;member_rank&quot;].value_counts(dropna=False).reset_index()
result.columns = [&quot;member_rank&quot;, &quot;count&quot;]
print(result)</code></pre>
<div class="table-scroll"><figure class="wp-block-table"><table class="wp-block-table"><thead><tr><th>member_rank</th><th>count</th></tr></thead><tbody><tr><td>Gold</td><td>3</td></tr><tr><td>Silver</td><td>2</td></tr><tr><td>Bronze</td><td>1</td></tr><tr><td>NaN</td><td>1</td></tr><tr><td>bronze</td><td>1</td></tr><tr><td>Silver</td><td>1</td></tr></tbody></table></figure></div>
<p><strong>この結果からわかること</strong></p>
<p>value_counts() の結果が、2列のDataFrameとして扱いやすい形になりました。これにより、あとで別の表と結合したり、CSVで保存したり、グラフ用データとして使ったりしやすくなります。</p>
<p>分析の途中ではSeriesのままでも十分ですが、<strong>あとで加工したいときはDataFrameにしておくと便利</strong>です。</p>

<h2><span id="toc14">件数と割合をまとめて表示する方法</span></h2>
<p>件数と割合を一緒に見たい場合は、次のように書けます。</p>

<pre class="language-python"><code class="language-python">counts = df[&quot;member_rank&quot;].value_counts(dropna=False)
rates = df[&quot;member_rank&quot;].value_counts(normalize=True, dropna=False) * 100

summary = pd.DataFrame({
    &quot;count&quot;: counts,
    &quot;rate(%)&quot;: rates.round(1)
})

print(summary)</code></pre>
<div class="table-scroll"><figure class="wp-block-table"><table class="wp-block-table"><thead><tr><th>member_rank</th><th>count</th><th>rate(%)</th></tr></thead><tbody><tr><td>Gold</td><td>3</td><td>33.3</td></tr><tr><td>Silver</td><td>2</td><td>22.2</td></tr><tr><td>Bronze</td><td>1</td><td>11.1</td></tr><tr><td>NaN</td><td>1</td><td>11.1</td></tr><tr><td>bronze</td><td>1</td><td>11.1</td></tr><tr><td>Silver</td><td>1</td><td>11.1</td></tr></tbody></table></figure></div>
<p><strong>この結果からわかること</strong></p>
<p>この表では、各カテゴリについて「何件あるか」と「全体の何%か」を同時に確認できます。たとえば、Gold は3件で 33.3%、Silver は2件で 22.2%、NaN は 11.1% です。</p>
<p>このように件数と割合をまとめて見ると、<strong>分布の全体像を一目で把握しやすくなります</strong>。ブログや資料に載せるときにも、この形式は非常に使いやすいです。</p>

<h2><span id="toc15">value_counts() は表記ゆれの発見にも便利</span></h2>
<p>value_counts() は、データクリーニングの入口としても便利です。</p>
<p>たとえば city 列を見てみます。</p>

<pre class="language-python"><code class="language-python">print(df[&quot;city&quot;].value_counts(dropna=False))</code></pre>
<div class="table-scroll"><figure class="wp-block-table"><table class="wp-block-table"><thead><tr><th>city</th><th>count</th></tr></thead><tbody><tr><td>Tokyo</td><td>3</td></tr><tr><td>Nagoya</td><td>2</td></tr><tr><td>Osaka</td><td>1</td></tr><tr><td>osaka</td><td>1</td></tr><tr><td>Tokyo</td><td>1</td></tr><tr><td>NaN</td><td>1</td></tr></tbody></table></figure></div>
<p><strong>この結果からわかること</strong></p>
<p>この結果では、Tokyo が3件、Nagoya が2件となっていますが、同時に Osaka と osaka、Tokyo と Tokyo が別々に存在していることもわかります。</p>
<p>つまり、<strong>同じ意味の値が表記の違いによって分かれてしまっている</strong>状態です。このまま集計を進めると、本来まとめるべきカテゴリが分散し、正しい分布を把握しにくくなります。</p>
<p>このようなときは、文字列をそろえてから再集計します。</p>

<pre class="language-python"><code class="language-python">df[&quot;city_cleaned&quot;] = df[&quot;city&quot;].str.strip().str.lower()
print(df[&quot;city_cleaned&quot;].value_counts(dropna=False))</code></pre>
<div class="table-scroll"><figure class="wp-block-table"><table class="wp-block-table"><thead><tr><th>city_cleaned</th><th>count</th></tr></thead><tbody><tr><td>tokyo</td><td>4</td></tr><tr><td>osaka</td><td>2</td></tr><tr><td>nagoya</td><td>2</td></tr><tr><td>NaN</td><td>1</td></tr></tbody></table></figure></div>
<p><strong>この結果からわかること</strong></p>
<p>クリーニング後は、Tokyo と Tokyo が tokyo に統一され、Osaka と osaka も osaka にまとまりました。その結果、都市ごとの実際の件数がかなりわかりやすくなっています。</p>
<p>このように、value_counts() は単なる件数集計だけでなく、<strong>前処理の前後でデータが整ったかを確認する道具</strong>としても使えます。</p>
<p><strong>ポイント</strong></p>
<ul>
<li>表記ゆれや入力ミスの発見に向いています</li>
<li>前処理の前後で比較すると、クリーニングの効果を確認しやすいです</li>
</ul>

<h2><span id="toc16">数値データにも使える</span></h2>
<p>value_counts() は文字列だけでなく、数値データにも使えます。</p>
<p>たとえば rating 列の件数を見てみます。</p>

<pre class="language-python"><code class="language-python">print(df[&quot;rating&quot;].value_counts())</code></pre>
<div class="table-scroll"><figure class="wp-block-table"><table class="wp-block-table"><thead><tr><th>rating</th><th>count</th></tr></thead><tbody><tr><td>4</td><td>4</td></tr><tr><td>5</td><td>3</td></tr><tr><td>3</td><td>2</td></tr></tbody></table></figure></div>
<p><strong>この結果からわかること</strong></p>
<p>この結果では、評価4が4件で最も多く、次に評価5が3件、評価3が2件あるとわかります。つまり、このデータでは極端に偏った分布ではなく、中間的な評価がやや多い傾向が見えます。</p>
<p>アンケートの回答、テストの点数、レビュー評価などでも同じように使えます。</p>

<h2><span id="toc17">value_counts() の結果はグラフ化にも使える</span></h2>
<p>value_counts() の結果はSeriesなので、そのまま棒グラフに使えます。</p>

<pre class="language-python"><code class="language-python">import matplotlib.pyplot as plt

!pip install japanize-matplotlib &gt; /dev/null # Google Colab の機能を使って日本語フォントをインストール・インポート
import japanize_matplotlib

df[&quot;member_rank&quot;].value_counts(dropna=False).plot(kind=&quot;bar&quot;)
plt.xlabel(&quot;member_rank&quot;)
plt.ylabel(&quot;count&quot;)
plt.title(&quot;member_rank の件数集計&quot;)
plt.show()</code></pre>
<figure class="image-block"><img decoding="async" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAjUAAAHlCAYAAAANww0qAAAAOnRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjEwLjAsIGh0dHBzOi8vbWF0cGxvdGxpYi5vcmcvlHJYcgAAAAlwSFlzAAAPYQAAD2EBqD+naQAAQr9JREFUeJzt3Xt8z/X///H7ezNzPo+2vXdA5rSaFJUQK6eMdJCERuozIoRPDkV0UurjUDqoyGHyyRKVs5qiJEqSQykZe29sfGIj9p5tr98fft7f3m3D5m2vvV/drpfL63LZ6/l6vl7vx/uV7O71ej5fL5thGIYAAAC8nI/ZBQAAAHgCoQYAAFgCoQYAAFgCoQYAAFgCoQYAAFgCoQYAAFgCoQYAAFgCoQYASkhSUpJOnz5tdhmAZRFqAMDDbr/9dq1evTpfe+vWrZWYmFjofikpKdqzZ48kyWaz6ciRI/rqq6/0ww8/SJLWrFmjmJiYS6rhX//6lz744APX+vvvv69BgwZddD/DMHTq1Cm35c8//8zXr127dvrss88uqRagpBBqAItLSkqSzWbTF198YXYpJeKLL76QzWZTUlKSR46XmZmp1NRUZWVlXVJ/h8Ohzz//XCEhIZKkgQMHatOmTZe077vvvqu+ffu6tY0YMUIbN26UJO3cuVNnzpy56HH279+v+fPn68Ybb3S1zZw5Uw0bNrzovmlpaapcubLbUqdOnXz9kpKSdOrUqYseDyhJhBoA+Jvdu3crNjZWtWvXVtWqVWW321WpUiXddNNNio+P14XeLrNq1SqFh4crMjJSZ8+eVXx8vCpXrnxJn/vYY4/p559/1i+//CJJ2rFjh44dO6Z//etfkqRdu3YpIiJCWVlZbsvf6xk3bpxyc3PVqFEjlStXTuXKldPWrVs1btw41/r55frrr3ftl5eXp3Llyun48eNui8Ph0IkTJy74vYHSgFADAH/x8ssvq1mzZipXrpyWL1+uW2+9VaNHj1ZSUpLuv/9+DRs2TPfee2+hV24WLFigXr16SZI2b94sX19fBQQE6MiRI8rLy9OJEyd05MgRHTlyRMeOHXPt980332jq1Knq37+/3nvvPUnSypUrdeedd2ry5MlKS0vT5s2b9dZbb6l8+fJuy/fff+86zvLly5WQkKDRo0e7BR/p3NWVvweiv+576NAhVa9evdAlIyPD4+cb8CRCDQD8f6+88oqef/55JSYmavbs2WrVqpUOHTqk8PBw2e12jRgxQj/88IM2b96sUaNG5dv/l19+0ddff63bb79dkvTpp5/qzJkzstvtCgwM1OHDh9WvXz8FBgYqMDBQN910k2vfChUq6KqrrlJERIRWrFghSSpfvrzq1q2rq666Smlpadq/f7++++47HT16VPHx8WrQoIGOHj2qZs2aSTp3e2rgwIFq0KCB3nzzTYWHh7sWSWrRooVbW9OmTd3qDw8Pl2EYhS7VqlXz/EkHPIhQA3jIpEmTZLfb9eWXX6pp06aqUKGCYmJidOLECa1fv15NmjRRuXLl1KlTJ6Wmprrte+rUKQ0bNkyBgYGqXLmybr75Zq1Zs8atT//+/dW6dWt9+OGHqlu3ripVqqTY2FhlZ2fr/fffV926dVWhQgX16tVLJ0+ezFef0+nUE088odq1a6tSpUrq0aNHgeNOXnvtNUVERKh8+fJq0qSJZs6cqdzcXNf2efPmyWazKS8vT0OGDFGVKlUuefxKu3bt1L9/f/3666+66aabXL/8pXMB4IYbblCFChUUERGhWbNmue17/nPT09M1YMAAVa9eXbVr19bgwYMvOM7E6XTq5ptvVoMGDZSenl5ovz179mjcuHFasmSJ2rRpI+ncf5eDBw+qcePGrn5hYWGaPn263nrrLTkcDrdjTJkyRZJUpkwZnT17VgsXLlRCQoIrFAQHB+vTTz91rf/222+ufaOiojRixAidOXNG9erVkyQtXrxYhw8f1kMPPaQvv/xS/v7+uu6661SrVi1lZGQoJCREtWrVUpkyZSSdu301YsQItW3bVoMHD1ZSUpJrkaRt27a5te3evTvfeUhPT1e1atXcFrvdLofDob59+7qWY8eOacaMGa71N998s9BzC5QYA4BHPP3000bVqlWNiIgIY+nSpcYnn3xiVK1a1ejWrZsRFhZmLF261Fi9erVx1VVXGd27d3ftd/bsWaNNmzZGs2bNjI8//tjYtm2b8eSTTxo+Pj7GkiVLXP1iY2ONoKAgo1GjRsa6deuMBQsWGGXKlDF69uxpREREGOvWrTOWLFliVKxY0Rg2bJhrvwMHDhiSjIYNGxp33nmn8eWXXxpLly41wsLCjJCQEOPYsWOuvuPGjTMCAgKMt99+2/j++++Nd955x6hevboxZMgQV5/33nvPkGS89NJLxtChQ41t27Zd8jm69dZbjX79+hm33HKL8f777xsHDx40DMMwli1bZthsNmPEiBHGd999Z0ydOtWw2WxGQkJCvs9t1qyZMXbsWGPr1q3Gq6++athsNuP555939duwYYMhyThw4IBhGIbRt29fIygoyLVemAEDBhhdunRxa/vyyy8Nm81mnDhxwq09KyvL8PHxMebOnetq++WXXww/Pz/DZrMZGzZsMGbPnm0EBQUZ2dnZrj7BwcHGp59+WuDnHzx40Ojevbtx/fXXGydPnjQkGXv37jX69Olj9OvXz2jRooUhydi6dathGIbx2GOPGYMGDXI7xvn/lgMHDjQqV65sBAcHuxZJRmBgoFtbRETEBc/JX504ccJYuHCha6lVq5YxYsQI1/rXX399yccCrhRCDeAhTz/9tCHJWL58uavtoYceMiQZn3zyiVs/Hx8f1y+7hQsXGpUrVzb++OMPt+MNHjzYaNy4sWs9NjbWkGT88MMPrrbo6GhDkvHjjz+69bPb7a7186EmJibG7fi7d+82fHx8jAkTJhiGYRhJSUmGr6+vsX79erd+H3zwgeHj42OkpqYahvF/4eKBBx4o0vkxjHOhpnbt2kZ8fLxb+9atW42nnnrKra1Lly5un3H+cwcPHuzWr3Xr1kbr1q1d638NNS+88IJRvXp146effrpobXa73Xj77bfd2saNG2c0b968wP4BAQHGCy+84Fpv37698dBDDxn+/v7Ghg0bjIEDBxrvvPOO2z4XCjWLFy82+vXrZ/z555/Gjh07jGrVqrlCyoYNGwwfHx+jW7duxnPPPef63rNnzy7wWAMHDjTGjBnj1ibJOHz48AXOwDmHDx82JLktFStWzNcvLCzMWLZs2UWPB5SkMiV7XQiwvi5durh+Dg4OliTdcccdrrbQ0FDl5eUpLS1Ndrtda9as0cmTJxUQEOB2HMMwlJeXJ6fTKX9/f0lSYGCga/zE+ePb7XZde+21bsc/fPhwvroGDx7stt6kSRPddNNN+uyzz/TMM89o/fr1ys3NVefOnfPtm5eXp507dyowMNDVdn4wbFHl5eXp/vvvd2tr0aKFWrRoka++vw5iPW/IkCFu63Xr1tXmzZvz9Vu+fLmeeuopbdiwQZGRkRet6/DhwwoNDXVr++ijjwr8nrm5ucrMzHTNajp58qTS0tK0dOlSLVq0SJL03HPPyel0ut2iys3N1f/+9z+3tgoVKqhGjRq6//77Xedl/PjxmjRpkmrWrClJatu2rd599101aNBADz30kIYNG6atW7dq3rx5BX4XPz8/zZgxQzNmzJAk16yl82Nr/m779u1q0qSJJKlOnTo6fvy423abzVbgfkBpQ6gBPKxs2bKun318zg1b8/X1zdeWk5Mj6dxzQRo1aqSEhIQCj+fn51fgsc8f66/HPt/21zEw51WoUCFfm91udz3YLS0tTZL01VdfqVKlSvn6hoWFua3/fZDppWrUqFG+mtPS0jRlyhStX79eycnJOnPmjHJzc9W2bdt8+1esWNFt3cfHx3Uu/+rpp59WtWrVlJiYWOBxCjru0aNHXeuJiYnat2+fYmNj8/X98ssv5XQ61bx5c0lS5cqV9e2337qdt7Fjx2r+/Pn59u3fv7/b+j333KMPP/xQU6dO1fjx411hdu3atRo1apRyc3Pl6+uruXPnqlWrVvL19VVsbKwaNGig+vXrF/hd3nzzTbcxLklJSapbt66OHTtW4H/bvyuoj2EYhBuUegwUBkxWs2ZNHTlyRI0bN1ZkZGS+5XwIulwFBR2Hw6EaNWq46pDOhaiC6vj7s1b+Hkwu1d/3y8vLU/v27RUfH68BAwZoxYoV+v777xUXF1es45+3YMECvfrqq3r++ee1devWi/Zv3bq11q9fL+ncL/BJkybpzjvvdA3aPS8rK0tjxoxR48aNdfPNN7va/x4E5s2bl2/20N8HChuGoQ8//FCS9MQTTygnJ0e9evXSuHHjlJOTo9WrV6thw4bKycnRgw8+KB8fHz3zzDNatmyZHnnkkXzfISYmRjabLd9St25dSefCV0Hb27Vr5zrGzJkz5efnl29Zu3btpZ14wESEGsBknTp10okTJzRnzhy39j179mjw4MEee+DZJ5984ra+b98+fffdd7rtttskSR06dJCPj4/+85//uPU7c+aMa7bLlXDs2DHt3btX48eP1+jRo9W2bVtde+21OnjwYIFB7FJFRUWpT58+6tSpk/r27XvRdy6NHDlSixYt0uLFizVmzBh99913evHFF9367Nu3T7fffrt27dqluXPnevzKxebNm7V48WKFhIQoOztb7777ru677z63PgcPHpQkrVixQk6n023bihUr3AJTTk6ORo8erWuuuUbSudtYsbGxOnbsmFu/vz9tumvXrm7bC7siBJQ2hBrAZH379tUtt9yioUOH6vnnn9e2bdu0ePFidezYUb6+vh77xbl8+XLFxcVpy5YtWrFihXr06KHatWvr8ccflyTVr19fo0eP1uLFixUbG6uNGzdq/fr1uv3227Vnzx5VqVLFI3X8Xe3atdWgQQMtWrRIGzdu1KZNmxQbG6ukpCT98ccfl338t956S2lpaQU+V+avbrvtNj377LPq06eP3njjDcXHx6thw4ZKSkrS9OnT1blzZzVp0kRpaWlKTEx0e8aMp9xwww16//33tWjRIgUHB2vp0qVut7/WrFmjCRMmKCEhQUlJSerVq1ehYS0xMVHXX3+90tLSXLc2P/nkE9WvX1+NGzfW2LFj9fvvv3v8OwBmItQAJjt/aX/EiBGaPXu2WrdurYkTJ2rEiBF67bXXPPIZPj4++vbbbyWd+1f4/fffr4iICG3atEm1atVy9XvppZf01ltvafv27erQoYMefPBBXXvttdqwYUO+8Tye9Mknn6hGjRq644471Lt3b9WtW1dLlizRvn378g1aLSq73a6pU6fqrbfe0qpVqy7Yd9y4cUpLS9Phw4d19913Szo3FunNN99U2bJlNX/+fO3evdvttpMnlS1bVtHR0YqMjJSvr69uueUWNW/eXB9//LGmTZumO++8UzNnztS9996rNWvWaOvWrWrRooXrJZgHDx7Ua6+9puuuu06PPfaYnnnmGS1YsMA10NzX11cTJkzQ1q1bdeLECV1zzTW6+eabNX36dLc6Vq5c6XZ7av/+/Vfk+wIeV5JTrQDA6s5P6S7IhaZ0Hzt2zLj55puN8uXLG3379jXS09MNwzCMJUuWGPHx8Ub58uWNRYsWue1z4MABIyoqyjVlfdiwYUavXr2MTz/91MjLy3PrJ8k4efKk2/4nTpww5s6da3z++eeutunTpxtdunQxzpw541rq1atnrF692m1fpnSjNLIZBm8oA3B5Bg4cWOBMn/PuvPNOLV26tAQr8k6JiYm67rrrVL169XzbDh06lG/KuXRuoLWnBpNL5wZCZ2dnX/R24/Hjx1WxYsUregUPKCpCDYDLlpKScsHbRFWqVCnwFzIAeBKhBgAAWAIDhQEAgCUQagAAgCUQagAAgCX8o979lJeXp9TUVNejwgEAQOlnGIZOnjypoKCgC872+0eFmtTUVIWEhJhdBgAAKIbk5GTZ7fZCt/+jQs35F/IlJydfsUe+AwAAz8rMzFRISEi+F+v+3T8q1Jy/5VSlShVCDQAAXuZiQ0cYKAwAACyBUAMAACyBUAMAACyBUAMAACyBUAMAACyBUAMAACyBUAMAACyBUAMAACyBUAMAACyBUAMAACzBtFCTmZmpRx99VGFhYQoJCVHz5s310UcfFdo/JSVFvXr1Unh4uIKDgzVy5EhlZ2eXYMUAAKA0My3U9OrVS6dPn9bu3buVnJysV155Rf369dPWrVvz9c3OzlaHDh0UGhqq/fv3a/fu3dq+fbtGjhxpQuUAAKA0shmGYZjxwceOHVPlypXl7+/vaouKilL//v31+OOPu/VdtGiRhg8frsOHD8vPz0+StH37drVq1UoOh0O1atW6pM/MzMxU1apVlZGRwQstAQDwEpf6+9u0KzW1atVyBZqsrCzNnj1bP//8s9q0aZOvb2Jiojp27OgKNJLUvHlz1ahRQ4mJiSVWMwAAKL3KmF1ASEiIUlJSFBUVpQ8//FA33HBDvj4pKSmKjIzM1x4cHKyUlJRCj+10OuV0Ol3rmZmZnikaAACUOqaHmuTkZJ04cULTpk3T/PnzFR0drYoVK7r18fPzk49P/otKNptNF7p7NmXKFE2ePNnjNf9V+NiVV/T4npL0YlezSwAA4IoqFVO6q1WrpmeeeUapqamaNWtWvu12u12pqan52lNTUxUcHFzocceNG6eMjAzXkpyc7NG6AQBA6WFKqMnLy9OKFSvytdeqVUuHDx/O196pUyetX79eOTk5rrbdu3fr6NGjio6OLvRz/P39VaVKFbcFAABYkymh5ujRo3r44Yc1efJk15iXtWvXau3ateraNf9tkpiYGAUEBGjChAnKzc1VRkaGHnvsMQ0YMEABAQElXT4AACiFTAk1derU0ZYtW7R3717Vq1dPQUFBGjt2rObNm6cOHTrI4XDIbrcrISFBklSmTBmtWbNGe/bsUUhIiJo2baqoqCjNnDnTjPIBAEApZNpzasxwJZ5Tw0BhAACurFL/nBoAAABPItQAAABLINQAAABLINQAAABLINQAAABLINQAAABLINQAAABLINQAAABLINQAAABLINQAAABLINQAAABLINQAAABLINQAAABLINQAAABLINQAAABLINQAAABLINQAAABLINQAAABLINQAAABLINQAAABLINQAAABLINQAAABLINQAAABLINQAAABLINQAAABLINQAAABLINQAAABLINQAAABLINQAAABLINQAAABLINQAAABLINQAAABLINQAAABLINQAAABLINQAAABLINQAAABLINQAAABLINQAAABLINQAAABLINQAAABLINQAAABLINQAAABLINQAAABLINQAAABLINQAAABLINQAAABLINQAAABLINQAAABLMDXUzJkzR02bNlVwcLAaN26st99++4L9u3fvrpo1a8put7uWNm3alFC1AACgNCtj1gcvXLhQkyZN0po1a9S0aVPt3btX7du3V+XKldW7d+8C93E4HIqPj1eXLl1KuFoAAFDamXalZsuWLZo6daqaNm0qSWrcuLH69OmjhISEQvdJSUlRSEhISZUIAAC8iGlXal5//fV8bT/99JOCgoIK7J+dna2jR48qNDT0SpcGAAC8UKkYKHz27Fk99thj+uabbzR69OgC+6SmpqpcuXKaPXu2rrvuOtWrV099+vTRoUOHCj2u0+lUZmam2wIAAKzJ9FBz6NAhtWnTRp9//rm++uorRUZGFtgvIyNDAQEBCgwM1ObNm/XTTz+pVq1aio6O1p9//lngPlOmTFHVqlVdC7euAACwLpthGIZZH/7999/rjjvuUL9+/fT888/L39+/SPvn5uaqatWq+vDDD9W5c+d8251Op5xOp2s9MzNTISEhysjIUJUqVS67fkkKH7vSI8e50pJe7Gp2CQAAFEtmZqaqVq160d/fpo2pOXTokO644w7NmjVLPXv2vKR98vLy5OPzfxeXDMNQXl6ebDZbgf39/f2LHJQAAIB3Mu3206BBg/Too49ecqDZvHmzGjZsqG3btkmSsrKyNHz4cNntdrVr1+4KVgoAALyBaaFm9erVeuONN9wepHd+kc49k8Zut7umeLdq1UpPPfWU4uLiXP1SU1O1bt06rsYAAADzbj9dbCiP3W6Xw+Fwa4uNjVVsbOyVLAsAAHgp02c/AQAAeAKhBgAAWAKhBgAAWAKhBgAAWAKhBgAAWAKhBgAAWAKhBgAAWAKhBgAAWAKhBgAAWAKhBgAAWAKhBgAAWAKhBgAAWAKhBgAAWAKhBgAAWAKhBgAAWAKhBgAAWAKhBgAAWAKhBgAAWAKhBgAAWAKhBgAAWAKhBgAAWAKhBgAAWAKhBgAAWAKhBgAAWAKhBgAAWAKhBgAAWAKhBgAAWAKhBgAAWAKhBgAAWAKhBgAAWAKhBgAAWAKhBgAAWAKhBgAAWAKhBgAAWAKhBgAAWAKhBgAAWAKhBgAAWAKhBgAAWAKhBgAAWAKhBgAAWAKhBgAAWAKhBgAAWAKhBgAAWAKhBgAAWAKhBgAAWAKhBgAAWAKhBgAAWAKhBgAAWIKpoWbOnDlq2rSpgoOD1bhxY7399tsX7J+SkqJevXopPDxcwcHBGjlypLKzs0uoWgAAUJqZFmoWLlyoSZMmacmSJUpJSdFHH32kiRMnavHixQX2z87OVocOHRQaGqr9+/dr9+7d2r59u0aOHFnClQMAgNLItFCzZcsWTZ06VU2bNpUkNW7cWH369FFCQkKB/RMSEpSenq4XXnhBvr6+qlatmqZNm6Z3331Xx44dK8nSAQBAKVTGrA9+/fXX87X99NNPCgoKKrB/YmKiOnbsKD8/P1db8+bNVaNGDSUmJuq+++7Lt4/T6ZTT6XStZ2ZmeqByAABQGpkWav7q7NmzGjlypL755ht98803BfZJSUlRZGRkvvbg4GClpKQUuM+UKVM0efJkj9aKKyd87EqzS7iopBe7ml0CAKAQps9+OnTokNq0aaPPP/9cX331VYHBRZL8/Pzk45O/XJvNJsMwCtxn3LhxysjIcC3JyckerR0AAJQepoaa77//Xi1atFDr1q31ww8/KCoqqtC+drtdqamp+dpTU1MVHBxc4D7+/v6qUqWK2wIAAKzJtFBz6NAh3XHHHZo1a5ZeeeUV+fv7X7B/p06dtH79euXk5Ljadu/eraNHjyo6OvpKlwsAAEo500LNoEGD9Oijj6pnz56X1D8mJkYBAQGaMGGCcnNzlZGRoccee0wDBgxQQEDAFa4WAACUdqaFmtWrV+uNN96Q3W7Pt0iSw+GQ3W53TfEuU6aM1qxZoz179igkJERNmzZVVFSUZs6cadZXAAAApYhps58KG9x7nt1ul8PhyNf28ccfX8myAACAlzJ99hMAAIAnEGoAAIAlEGoAAIAlEGoAAIAlEGoAAIAlEGoAAIAlEGoAAIAlEGoAAIAlEGoAAIAlEGoAAIAlEGoAAIAlEGoAAIAlEGoAAIAlEGoAAIAlEGoAAIAlEGoAAIAlEGoAAIAlEGoAAIAlEGoAAIAlEGoAAIAlEGoAAIAlEGoAAIAlEGoAAIAlEGoAAIAlEGoAAIAlEGoAAIAlFCvUZGVlFdienZ19WcUAAAAUV7FCTURERL62EydO6LbbbrvsggAAAIqjTFE6JycnyzAM5eTkuH4+Ly0tTb/88ovHCwQAALgURQo1Dz/8sNavXy+bzaawsDC3bRUqVNCwYcM8WhwAAMClKlKoWbt2rSQpMjJSu3btuiIFAQAAFEexxtQQaAAAQGlTpCs1f7Vq1Srt2rUr30yoiRMnXnZRAAAARVWsUPPoo49q4cKFuvbaa1W2bFlXu81mI9QAAABTFCvULF26VHv27FFISIin6wEAACiWYo2pqVq1KoEGAACUKsUKNbGxsXr22Wc9XQsAAECxFev2065du/TJJ59o0aJFCgoKctuWmJjokcIAAACKolihplGjRmrUqJGnawEAACi2YoWap59+2tN1AAAAXJZijakBAAAobYp1pcbHx0c2m63Abbm5uZdVEAAAQHEUK9Rs2LDBbT0pKUlTpkzR1KlTPVIUAABAURUr1Nx666351lu1aqXBgwere/fuHikMAACgKDw2pqZBgwbau3evpw4HAABQJMW6UrNx40a39bNnz2rVqlW66qqrPFIUAABAURUr1LRr185t3d/fX82aNdPcuXM9URMAAECRFev2U15entty5swZffPNN4qKiirSMbZs2aJRo0apRo0amjdv3gX7d+/eXTVr1pTdbnctbdq0KU75AADAgop1pea83NxcHT16VLVq1VKZMkU71HvvvafZs2erY8eO8vX1vWh/h8Oh+Ph4denSpbjlAgAACyvWlRrDMDRx4kRVq1ZNwcHBqlatmsaNGyfDMC75GAMHDtTWrVv13HPPqWLFihftn5KSwpvBAQBAoYoVat544w198MEHWrBggXbt2qUFCxZo+fLlevXVVz1dnyQpOztbR48eVWho6BU5PgAA8H7FCjVvvvmm1q5dq7vuukuNGzfW3XffrdWrV+vtt9/2dH2SpNTUVJUrV06zZ8/Wddddp3r16qlPnz46dOjQBfdzOp3KzMx0WwAAgDUVK9RkZmYqPDzcrS08PFwnT570RE35ZGRkKCAgQIGBgdq8ebN++ukn1apVS9HR0frzzz8L3W/KlCmqWrWqa+H2FQAA1lWsUBMUFKQvvvjCre3LL79UnTp1PFFTPlFRUTp48KD69u2r8uXLq2LFipo2bZqOHDmiTZs2FbrfuHHjlJGR4VqSk5OvSH0AAMB8xZr99Oyzz6pr16565JFH1KhRI+3bt0/vvPOOEhISPF2fS15ennx8/i+DGYahvLy8Ql+sKZ17fo6/v/8VqwkAAJQexbpS06FDBy1btkx79uzRtGnTtHPnTn3wwQfq3Lmzp+uTJG3evFkNGzbUtm3bJElZWVkaPny47HZ7vgcBAgCAf6ZihZq0tDTFx8drzZo12rdvn1avXq0XX3xRBw8e9EhRDodDdrvddeWnVatWeuqppxQXF+d68F5qaqrWrVvHlRgAACCpmLefhg4dqvr167tu/fj5+al///4aOnSoPv300yIfLykpyW3dbrfL4XC4tcXGxio2NrY45QIAgH+AYl2p2bJli1544QW38SwPPfSQfvzxR48VBgAAUBTFCjU+Pj5yOp1ubVdqOjcAAMClKFaouf3229W3b1/98ccfkqTjx4+rf//+V2ygMAAAwMUUK9S88sorcjgcql27tq666ioFBAQoJSVFU6dO9XR9AAAAl6RYA4WrV6+ub7/9Vl999ZUOHTqksLAw3XLLLZ6uDQAA4JIVK9Sc17p1a0/VAQAAcFmKdfsJAACgtCHUAAAASyDUAAAASyDUAAAASyDUAAAASyDUAAAASyDUAAAASyDUAAAASyDUAAAASyDUAAAASyDUAAAASyDUAAAASyDUAAAASyDUAAAASyDUAAAASyDUAAAASyDUAAAASyDUAAAASyDUAAAASyDUAAAASyDUAAAASyDUAAAASyDUAAAASyDUAAAASyDUAAAASyDUAAAASyDUAAAASyDUAAAASyDUAAAASyDUAAAASyDUAAAASyDUAAAASyDUAAAASyDUAAAASyDUAAAASyDUAAAASyDUAAAASyDUAAAASyDUAAAASyDUAAAASyDUAAAASyDUAAAASzAt1OTl5WnLli0aNWqUatSooXnz5l2wf0pKinr16qXw8HAFBwdr5MiRys7OLpliAQBAqWdaqHnvvfc0bNgwlS9fXr6+vhfsm52drQ4dOig0NFT79+/X7t27tX37do0cObKEqgUAAKWdaaFm4MCB2rp1q5577jlVrFjxgn0TEhKUnp6uF154Qb6+vqpWrZqmTZumd999V8eOHSuhigEAQGnmFWNqEhMT1bFjR/n5+bnamjdvrho1aigxMdHEygAAQGlRxuwCLkVKSooiIyPztQcHByslJaXQ/ZxOp5xOp2s9MzPzitQHAADM5xWhxs/PTz4++S8q2Ww2GYZR6H5TpkzR5MmTr2RpQKkUPnal2SVcVNKLXc0u4aK84TxKnEtP8YbzKHEuL8Qrbj/Z7Xalpqbma09NTVVwcHCh+40bN04ZGRmuJTk5+UqWCQAATOQVV2o6deqkuLg45eTkqEyZcyXv3r1bR48eVXR0dKH7+fv7y9/fv6TKBAAAJvKKKzUxMTEKCAjQhAkTlJubq4yMDD322GMaMGCAAgICzC4PAACUAqUy1DgcDtntdiUkJEiSypQpozVr1mjPnj0KCQlR06ZNFRUVpZkzZ5pcKQAAKC1Kxe2npKQkt3W73S6Hw5Gv7eOPPy7BqgAAgDcplVdqAAAAiopQAwAALIFQAwAALIFQAwAALIFQAwAALIFQAwAALIFQAwAALIFQAwAALIFQAwAALIFQAwAALIFQAwAALIFQAwAALIFQAwAALIFQAwAALIFQAwAALIFQAwAALIFQAwAALIFQAwAALIFQAwAALIFQAwAALIFQAwAALIFQAwAALIFQAwAALIFQAwAALIFQAwAALIFQAwAALIFQAwAALIFQAwAALIFQAwAALIFQAwAALIFQAwAALIFQAwAALIFQAwAALIFQAwAALIFQAwAALIFQAwAALIFQAwAALIFQAwAALIFQAwAALIFQAwAALIFQAwAALIFQAwAALIFQAwAALIFQAwAALIFQAwAALIFQAwAALIFQAwAALIFQAwAALMHUUDNv3jxFRkbKbrerZcuW+vrrrwvt2717d9WsWVN2u921tGnTpgSrBQAApVkZsz44Pj5e48ePV2Jioho1aqSlS5eqa9eu+uGHH1S3bt18/R0Oh+Lj49WlSxcTqgUAAKWdaVdqJk+erNGjR6tRo0aSpHvuuUdt27bVrFmzCuyfkpKikJCQkiwRAAB4EVNCTXJysn777TfFxMS4tXfr1k2rV6/O1z87O1tHjx5VaGhokT7H6XQqMzPTbQEAANZkSqhJSUmRJAUFBbm1BwUFubb9VWpqqsqVK6fZs2fruuuuU7169dSnTx8dOnTogp8zZcoUVa1a1bVwpQcAAOsyJdT4+fmd+3Af94+32WwyDCNf/4yMDAUEBCgwMFCbN2/WTz/9pFq1aik6Olp//vlnoZ8zbtw4ZWRkuJbk5GTPfhEAAFBqmBJq7Ha7pHNXYP4qNTVVwcHB+fpHRUXp4MGD6tu3r8qXL6+KFStq2rRpOnLkiDZt2lTo5/j7+6tKlSpuCwAAsCZTQk2dOnUUFRWlVatWubWvXbtWnTt3LnCfvLw8t3XDMJSXlyebzXbF6gQAAN7DtNlPY8aM0dSpU7Vv3z5J0vLly7Vu3ToNHTo0X9/NmzerYcOG2rZtmyQpKytLw4cPl91uV7t27UqybAAAUEqZ9pya3r17KzMzUzExMTp16pSCg4O1YsUK1a9fXw6HQzfddJOmT5+unj17qlWrVnrqqacUFxen9PR0ZWVlqU2bNlq3bp38/f3N+goAAKAUMS3USFJcXJzi4uLytdvtdjkcDre22NhYxcbGllRpAADAy/DuJwAAYAmEGgAAYAmEGgAAYAmEGgAAYAmEGgAAYAmEGgAAYAmEGgAAYAmEGgAAYAmEGgAAYAmEGgAAYAmEGgAAYAmEGgAAYAmEGgAAYAmEGgAAYAmEGgAAYAmEGgAAYAmEGgAAYAmEGgAAYAmEGgAAYAmEGgAAYAmEGgAAYAmEGgAAYAmEGgAAYAmEGgAAYAmEGgAAYAmEGgAAYAmEGgAAYAmEGgAAYAmEGgAAYAmEGgAAYAmEGgAAYAmEGgAAYAmEGgAAYAmEGgAAYAmEGgAAYAmEGgAAYAmEGgAAYAmEGgAAYAmEGgAAYAmEGgAAYAmEGgAAYAmEGgAAYAmEGgAAYAmEGgAAYAmEGgAAYAmEGgAAYAmEGgAAYAmmhpp58+YpMjJSdrtdLVu21Ndff11o35SUFPXq1Uvh4eEKDg7WyJEjlZ2dXYLVAgCA0sy0UBMfH6/x48frww8/lMPh0JgxY9S1a1cdOHAgX9/s7Gx16NBBoaGh2r9/v3bv3q3t27dr5MiRJlQOAABKI9NCzeTJkzV69Gg1atRIknTPPfeobdu2mjVrVr6+CQkJSk9P1wsvvCBfX19Vq1ZN06ZN07vvvqtjx46VdOkAAKAUMiXUJCcn67ffflNMTIxbe7du3bR69ep8/RMTE9WxY0f5+fm52po3b64aNWooMTHxitcLAABKvzJmfGhKSookKSgoyK09KCjIte3v/SMjI/O1BwcHF9j/PKfTKafT6VrPyMiQJGVmZhar7oLkOU977FhXkie/85XiDefSG86jxLn0FG84jxLn0lO84TxK/8xzef54hmFcsJ8poeb8FRcfH/cLRTabrcCC/fz88vW9UP/zpkyZosmTJ+drDwkJKWrJXq/qDLMrsAbOo+dwLj2Hc+kZnEfPuVLn8uTJk6patWqh200JNXa7XZKUmpqqq6++2tWempqq4ODgAvunpqbmay+s/3njxo1zG0ycl5enP/74QzVr1pTNZrucr3DFZGZmKiQkRMnJyapSpYrZ5Xg1zqVncB49h3PpOZxLz/CW82gYhk6ePJnvDs/fmRJq6tSpo6ioKK1atUrDhg1zta9du1adO3fO179Tp06Ki4tTTk6OypQ5V/Lu3bt19OhRRUdHF/o5/v7+8vf3d2urVq2aZ77EFValSpVS/QfMm3AuPYPz6DmcS8/hXHqGN5zHC12hOc+02U9jxozR1KlTtW/fPknS8uXLtW7dOg0dOjRf35iYGAUEBGjChAnKzc1VRkaGHnvsMQ0YMEABAQElXToAACiFTLlSI0m9e/dWZmamYmJidOrUKQUHB2vFihWqX7++HA6HbrrpJk2fPl09e/ZUmTJltGbNGg0ZMkQhISHy8fFRz5499eKLL5pVPgAAKGVMCzWSFBcXp7i4uHztdrtdDocjX9vHH39cUqWZxt/fX08//XS+22YoOs6lZ3AePYdz6TmcS8+w2nm0GRebHwUAAOAFeKElAACwBEINAACwBEINAACwBEINAACwBEINAACwBEINLGXZsmVmlwAAMAlTuk3i4+NzSe+fys3NLYFqrKNJkyb68ccfXS9NBUqL48eP69dff1VWVpZbe9u2bU2qyDsZhqFNmzYpKSlJDz74oH755Rc1bNjQ7LJQShBqTPLll1+6ft65c6fmzJmjZ599VlWqVNHhw4c1efJkvfzyy4qJiTGxSu+zYcMG/fe//9WkSZMUGBhodjleb9myZXr11VeVnp6u3bt3a9iwYfr3v//9j3zT/eWYM2eOhgwZouzsbLd2m83GP1yK4NChQ+rRo4eSk5Nls9mUnp6u++67T7fffrv+9a9/mV2e10hLS1OdOnXMLuPKMGC69u3bG0lJSW5t27dvN6Kjo02qyHvddNNNxjXXXGP4+voaoaGhRt26dV0LiubNN980QkNDjZkzZxohISGGYRjGf//7X+Pee+81uTLvExISYixdutTIzs42uxSvdueddxpPPvmkkZuba4SHhxuGYRhHjhwxIiMjTa7Mu4SFhZldwhXDlZpSoKDXQkjSVVddpSNHjphQkfeaP39+odtiY2NLsBLv16hRI61atUr16tVT3bp1deDAARmGobp16yopKcns8rxKaGioDh06ZHYZXi8kJETJycmSpHr16un333+XxPktqunTpys3N1ejR482uxSPM/XdTzinevXqWrt2rTp16uRqW7lypWrXrm1iVd6J4OI5J0+eVL169dzaDMNQTk6OSRV5r/bt22vdunXq2LGj2aV4NX9/fx06dEihoaGutqSkJFWoUMHEqrxPenq6vv32W82ZM0ctW7aUr6+va9vcuXNNrOzyEWpKgeeee049evRQ9+7dVa9ePe3bt08rV65kJk8xORwOzZ07VykpKZo9e7YWLVqke++91zIvbCspTZo00dSpU/XEE0+4BrXPnj1bUVFRJlfmfZo2bar7779fPXv2VHBwsNu2iRMnmlSV9+nfv786dOigF198UTk5Ofr66681atQoPfzww2aX5lWOHDmisLAwhYWFSTr3jxWr4PZTKbF9+3bNmTNHv//+uwIDA/XII4/o5ptvNrssr7Np0yZ169ZN0dHR2rJli1JTUzV+/HhlZ2frlVdeMbs8r7Jz5061bdtWYWFhOnDggG688Ubt3LlTX3zxhRo3bmx2eV6lffv2BbbbbDYlJiaWcDXeKzc3V0888YRmz56t06dPq3Llyho2bJgmTZrkdrUB/1yEGljKjTfeqEmTJqlLly6ucSBZWVmKjIzUb7/9ZnZ5XsfhcGj+/PlyOByqX7++HnzwQW6LwnRnz57VH3/8Yd0ZPCXAsOjUeEKNSRYsWHBJ/R588MErXIm1BAUFKTU1VZL7QMLCBmOjcGfOnFH58uXztX///fe6/vrrTajIetLT0wmJRfDkk09q1KhRqlGjhlt7nz59tGjRIpOq8j6FTY2/7bbbFBcXZ3Z5l4VQY5K6detetI/NZnP9UsaladasmaZNm6bo6GhXqNm0aZNGjRqlrVu3ml2eV/H399fTTz+t8ePHu7Uz06ToUlJSNHLkSO3YsUNnz56VJJ0+fVpZWVk6ceKEucV5kbJly6pOnTqaN2+ebrvtNlc7fyaLpkePHoqMjNQzzzyj+vXr68CBA0pLS9Ptt9+un376yezyLguvSTDJgQMHLroQaIpu4sSJ6tatm4YPH65Tp07p+eef1z333KOnn37a7NK8TuXKlbVu3Tq1b9/edfVLstagwpLy8MMPyzAMvfzyyzpz5ozeeOMNNW/eXCtXrjS7NK9Sp04dzZkzR71799aYMWNcM/H4M1k033//vZ577jm3J9vXqVNHGRkZJld2+Qg1pUhubq6OHDnClNnLcPfdd2vx4sXas2ePatasqW+++Ubvv/++unbtanZpXqdChQr6/PPP1bJlS0VFRblm413K6z3gbufOnfrggw/UvXt3lStXTp07d9b8+fP1+OOPm12aV7HZbOrYsaO2b9+uLVu2qFWrVkpKSuLPZBGdnxr/V1aZGk+oKQUMw9DEiRNVrVo1BQcHq1q1aho3bhz/+iiGzz77TN27d9f69eu1d+9erVixQrfffrvZZXktX19fvfTSS4qPj9fgwYM1cuRIHutfDOXKlXM9SLNixYo6cuSIAgICGOdVROf/TrTb7dqwYYO6dOmili1b6vjx4yZX5l3OT41ftmyZa2r8/fffb4mp8YSaUuCNN97QBx98oAULFmjXrl1asGCBli9frldffdXs0rzOvffeqyZNmuj111/Xn3/+aXY5Xu2vobpTp07asWOHdu3axVOuiyEuLk7R0dHKzc1VmzZt9Mgjj2jUqFH5nlmDCxsyZIjrZx8fH02ePFkJCQn5HhKJCxs3bpxiYmLUr18/ORwO3XHHHerQoYNGjhxpdmmXjYHCpUBkZKRWrFih8PBwV1tSUpK6du2q3bt3m1eYFzpz5oyWLl2qBQsWaNu2berTp4+GDh2qRo0amV2a18nOzlbZsmXztS9btkx33XWXCRV5t8TEREVHRys9PV2xsbH6888/NWvWLF177bVml4Z/mMzMTFWpUsWSU+MJNaVAYSP3GdF/eRwOh95//3299tpratiwoT777DOzS8I/2PHjx/Xrr78qKyvLrb1t27YmVeSdVq1apV27drmdR5vNpgkTJphYlXepVKmS+vXrp6FDh6pp06Zml+NRvCahFAgKCtIXX3yhdu3audq+/PJLS6Xnknbs2DEtWbJE77//vnx9fRlXUwxbt27V0KFDtWvXLjmdTrdtjKspmjlz5mjIkCHKzs52a7fZbJzLInj00Ue1cOFCXXvttW5XEQk1RbNmzRrNnz9ft9xyi5o1a6ahQ4fq7rvvlo+P949I4UpNKbB+/Xr16NFDjzzyiBo1aqR9+/bpnXfeUUJCgjp37mx2eV5l5cqVmjt3rlatWqVbb71Vjz76qGJiYizxP2tJu/baa9WuXTt169Yt322oW2+91aSqvFNoaKhmzJihbt26yc/Pz+xyvFadOnX03XffKSQkxOxSLOHMmTNatmyZ4uPjtXfvXj388MN68sknzS7rshBqSom1a9fqP//5jw4ePKjQ0FCNGDGCacjFUL16dfXv31+PPvqoGjRoYHY5Xu2vT2fG5eFWsmdERERo3759ZpdhKdu3b9eCBQv03//+V9ddd51Wr15tdkmXhX++migjI8P1F12nTp3UoEEDtWrVikf6X4bU1FRNnz6dQOMBjRo1UlJSktllWEL79u21bt06s8vwerGxsXr22WfNLsPrHT9+XK+99pqaNWumDh06yNfXV1999ZXXBxqJMTWmOXr0qG688UbFxsa6nnb70UcfafDgwTIMQ88995wiIyN1yy23mFxp6ffMM89cUr+JEyde4UqsZdiwYYqJidFTTz2loKAgt20Mbi2apk2b6v7771fPnj3zTePmz+Wl27Vrlz755BMtWrQo359J3nZ+6QIDA9WkSRMNHTpUffr0KfAdb96K208mGTRokHx9ffX666+72s6/VVqS1q1b5xpXgwtr3779RfvYbDb+0iuiwsYhMbi16Ar7M8qfy6KZPHlyodt4Fcql27x5s1q1amV2GVcEocYk9erV048//qjKlSu72h5++GG9++67ks49+KxBgwb67bffzCoRAGARGzduvKR+3n4VllBjkpCQECUnJ192HwD4J3E6nVq2bJmSkpIUFhamHj16WOr2yZVyKTNArXAVljE1JilXrpxSUlIKfUz677//bomXi5WEXr166YMPPpAkPfTQQ4X2mzt3bkmVZBlz587V1KlTlZSUpNDQUI0aNUpxcXFml4V/qPT0dLVu3VrHjx9XvXr19Pvvv+upp57SV199pcDAQLPLK9Xy8vLMLqFEMPvJJOdfHnbmzJl825xOpwYPHqxevXqZUJn3sdvtrp8Nwyh0QdEsWbJEY8eOVVxcnJYtW6ZBgwZp4sSJev/9980uDf9QY8aMUYcOHZSamqpvv/1WqampuuOOO/Tvf//b7NJQSnD7ySRnzpxRu3bt5HA4NGTIEDVu3Fi+vr7avXu33nzzTdWuXVsbN27kas0lOn36dL5ztX37djkcDrVq1Uq1atUyqTLv1bx5c7333nuKiopyte3cuVMPPvigduzYYV5h+MeqV6+e9u3bpzJl/u8mw9mzZxUREeGaZIGCzZgxQyNGjJAkLViwoNB+Dz74YAlVdGUQakx05swZTZ48WfPmzVN6erokqUaNGurXr5+effZZVapUyeQKvcO2bdt077336ueff3bdW3/yySf14osvqlq1apLOPRa8RYsWJlbpfXgnGUqb8PBw7d+/X76+vq62nJwc1a9fXwcPHjSxstKvVatW2rx5s6RzM20LYrPZ9Pvvv5dkWR5HqCkljh07JsMwVKtWLdlsNrPL8SodO3ZUv3791K9fP0nSd999p5YtW2rx4sXq1auX4uPjNWfOHG3YsMHkSr1LVFSU4uPjdc0117jafvrpJ/Xp00c7d+40sTL8U/Xr10/Vq1fX9OnT5evrq9zcXI0aNUppaWlavHix2eWhFCDUwOv9/QnM99xzj7KysrRy5UpXW1hYGP+SK6LFixdrxIgRGj9+vBo2bKh9+/ZpypQpmjp1qitAAiXp/EDhEydOqF69ejpw4IAqVarEQOHLkJubqz///FNVqlQxuxSPYPYTvF6ZMmWUk5OjMmXKKCkpSZ988olWrVrl2n727Nl8b0fGxfXu3VunTp3Syy+/7Jr9NGHCBAINTFO7dm3t3LlTS5cudb0n7+6772bs4SU4cuSI4uLitGTJEvn7+0uSPv30U/Xv318nTpxQq1at9OGHH6pOnTomV3p5uFIDr/fQQw/J6XTqgQce0EsvvaSsrCxt3brVtX3GjBlav36925UbXFxaWprX/wUHaxkzZoxeeukls8vwSgMGDFCVKlU0c+ZMSVJKSooiIiI0YMAAxcXF6c0339SJEye8fnYjoQZe7/jx4xo4cKA+++wzXXPNNYqPj3cNhDt27JgaNmyodevW6frrrze5Uu8SHh7OCy1RqrRu3VoJCQncaiqG0NBQ7du3T+XKlZMkDR8+XF988YV27Nghm82m7OxsRUREeP3/84QaWN7//vc/1axZ0+wyvM706dOVm5ur0aNHm10KIEnav3+/pk6dqujoaLVs2dJtFlRoaKiJlZV+f31C/cmTJ2W32zVjxgwNGDDA1ScoKEipqalmlegRjKmB5RFoiic9PV3ffvut5syZk+8XCE9nhhkaNGggSXrnnXfc2q3weP8rrVGjRnr99dfVv39/jRkzRpUqVVKfPn1c29euXauQkBATK/QMQg2AAh05ckRhYWEKCwuTJJ7KDNPxgL3imzFjhjp16qRhw4apUqVKWrp0qcqWLSvp3G36vn376rXXXjO5ysvH7ScAF5WSkqK0tDRFRUW5XbEBStrKlSv11ltvKSkpSeHh4Ro0aJC6du1qdlleISsrS3v27FHdunVVvXp1t22ff/65brvtNpMq8xze/QTA5Y8//lCHDh1UqVIltW/fXmlpaXr99dcVHh6uFi1aqHHjxrw5HqZ5++231bt3b1199dWu18v06dNHc+bMMbs0r1CuXDk1b948X6CRZIlAI3GlBsBfDB48WN99953Gjh0rp9OpQ4cOacqUKerbt69eeuklzZgxQ7/88osWLlxodqn4B7r66qu1aNEi3Xjjja62nTt36t5779W+fftMrAylBaEGgEvdunX1xRdfuMbR7NixQ82bN9fvv/+u8PBwZWdnq379+lytgSkKm53z15k9+Gfj9hMAl6ysLFegkaRmzZqpYsWKrrayZcsyYBim6dSpk5YvX+7WtmnTJrVs2dKcglDqMPsJgIufn1++toCAALeXrPr48G8hlJxnnnnG9XNAQIBiY2PVp08fXXXVVTpx4oQWLFigF154wcQKUZpw+wmAS6VKlXTfffe5tSUkJKhnz55u6ydPnizp0vAP1b59+4v2sdlsSkxMLIFqUNoRagC4/PXpohfy3nvvXeFKAKDoCDUAAMASuDkOAAAsgVADAAAsgVADAAAsgVADAAAsgVADoFSaN2+ewsPDzS7jss2bN0/t2rUzuwzgH4FQAwAALIFQAwAALIFQA6BQ7dq108SJE9WuXTsFBASoXbt2cjgceuCBBxQYGKjrrrtOO3bskCTl5OToueeeU/369RUcHKzu3bvr4MGDrmP1799fQ4YMUY8ePVSnTh01b95cv/76q4YPH67g4GBFRETos88+y1fD/PnzFRERoTp16qhfv346fvy4a9uxY8c0YMAAhYSEKCwsTMOHD9fp06dd28PDw/Xpp5+qT58+atOmzUW/b//+/TV27FhNmzZNoaGhOnz4sAzD0NSpU1WvXj0FBgaqc+fObi9PbNeunV566SU9+OCDCgkJkd1u17vvvlvg8Z1Op2699VY98MADys3NvWg9AIqGUAPggt5++23NmjVLhw8fVk5Ojpo3b65u3brp8OHDat++vQYNGiRJGjNmjObPn6/PPvtMDodDkZGR6tGjh9sv7wULFmjEiBFKS0tTRESEbrnlFl111VVKSUnR0KFD1a9fP7cXZqampurzzz/Xjh079Ntvvyk1NVUPP/ywJCkvL09dunTRH3/8oZ9//lm7du3S3r17NWbMGLf6X3/9dcXFxWnTpk2X9H2//fZb5eTk6ODBgwoMDFRiYqLmzJmjjRs3yuFwqHLlyho5cqTbPlOmTFHv3r2VnJysmTNnasiQIfrf//7n1icvL099+/ZVYGCgFi5cKF9f30v/jwDg0hgAUIhbb73VePzxx13r48ePNyIjI13ra9euNfz9/Q2n02lUqFDB+PDDD13bcnNzjZo1axobNmwwDMMwYmNjjbvuusu1/e233zZq1KhhZGdnG4ZhGL/88oshyTh8+LBhGIbx3nvvGVWqVDGcTqdrnx9++MGQZKSnpxubNm0yfHx8jLS0NNf2HTt2GH5+fq5jhoWFGY888sglf9/Y2FgjIiLCyMvLc2s/fzzDMIzly5cbV199tds5evjhh13rTqfTkGR88803ru9x6623GsOGDTPuuece4+zZs5dcD4Ci4S3dAC6oSpUqrp/9/PxUs2ZN13rZsmXldDr1xx9/6PTp0xo+fLhGjRrltn9SUlKhx6pcubLrzeBly5aVJGVlZbn6VK9e3dUuSQ0bNnQd0+FwyGazqWXLlm6fV6FCBR08eFBXX321JOnGG28s0vdt2bKl21vJ09LSNGnSJG3cuFGnTp2S0+lUuXLl3PYJDg52/VzQ99iyZYtSUlJUv359rtAAVxChBsBlq1OnjipVqqTFixdf0tiVS5WZmSnDMFwh4/fff5ck11RvPz8/7du3zy34/F1RQ8Tf+8fGxsrX11fr1q1TcHCwVq9ercGDBxfpmI0aNdK3336rVq1aacqUKRo/fnyR9gdwaRhTA+Cy2Ww211WaAwcOSDp3haNnz57au3dvsY+bkZGhMWPG6OzZszp9+rSeeOIJ3XXXXQoICNANN9ygFi1aaNCgQTp58qQk6YcfflBMTIycTqdHvpcknTp1ShEREQoODtbRo0f16quvug1GvhTVqlWTv7+/4uPjNWXKFG3cuNFj9QH4P4QaAB4xadIk3XvvvercubPsdruio6MVHR2txo0bF/uY3bp1U82aNdW4cWPVr19fNWvW1Jw5cySdC1LLli2Tn5+fIiMjFRISoiFDhmj06NHy9/f31NfSrFmztGnTJgUGBqpLly4aP368srKydOTIkSIfq3HjxnrhhRfUu3dvHT161GM1AjjHZhh/mWoAAADgpRhTA+Af4+abb3Z7xsxf7dmzx20gMwDvw5UaAABgCYypAQAAlkCoAQAAlkCoAQAAlkCoAQAAlkCoAQAAlkCoAQAAlkCoAQAAlkCoAQAAlkCoAQAAlvD/APULnGlrV2bCAAAAAElFTkSuQmCC
" alt="Colab notebook output image" /></figure>
<p><strong>この結果からわかること</strong></p>
<p>棒グラフにすると、どのカテゴリが多いかを視覚的に確認しやすくなります。表だけでも十分ですが、カテゴリ数が多いときや他人に説明するときは、グラフのほうが伝わりやすいことがあります。</p>
<p>ただし、今回の記事の主役はあくまで value_counts() なので、可視化は「こういう使い方もできる」と押さえておく程度で十分です。</p>

<h2><span id="toc18">value_counts() と groupby().size() と count() の違い</span></h2>
<div class="table-scroll"><figure class="wp-block-table"><table class="wp-block-table"><thead><tr><th>書き方</th><th>主な用途</th><th>特徴</th></tr></thead><tbody><tr><td>value_counts()</td><td>1列の値の出現回数を数える</td><td>最も手軽でわかりやすい</td></tr><tr><td>groupby().size()</td><td>グループごとの件数を数える</td><td>複数列の組み合わせ集計にも向く</td></tr><tr><td>count()</td><td>欠損値を除いた件数を数える</td><td>列ごとの非欠損件数を見るときに使う</td></tr></tbody></table></figure></div>

<h3><span id="toc19">どう使い分ければよいか</span></h3>
<p>まず、1列だけの分布確認なら value_counts() が最も簡単です。</p>
<p>たとえば「会員ランクごとの人数を知りたい」なら、value_counts() が最短です。</p>
<p>一方、複数列の組み合わせで件数を見たいときは groupby().size() が向いています。たとえば「都市ごと・会員ランクごとの件数を見たい」といった場面です。</p>
<p>また、count() は「値の種類ごとの件数」を数えるというより、<strong>欠損でないデータが何件あるか</strong>を見るときに使います。そのため、value_counts() と同じ用途だと思うと混乱しやすいです。</p>

<h3><span id="toc20">初心者向けの覚え方</span></h3>
<ul>
<li>1列の分布を見る → value_counts()</li>
<li>複数条件で件数を出す → groupby().size()</li>
<li>欠損を除いた件数を知る → count()</li>
</ul>

<h2><span id="toc21">よくある使い方の例</span></h2>
<ul>
<li>会員ランクの分布確認</li>
<li>アンケート回答の件数確認</li>
<li>都道府県別・カテゴリ別の件数確認</li>
<li>欠損値を含めたデータ品質チェック</li>
<li>表記ゆれや入力ミスの発見</li>
</ul>
<p>つまり、value_counts() は分析の最初にデータの中身をざっくり把握するための定番メソッドと言えます。</p>

<h2><span id="toc22">大規模データでの考慮事項</span></h2>
<p>value_counts() は便利ですが、<strong>ユニークな値が非常に多い列</strong>に使うと、結果が長くなりやすいです。</p>
<p>たとえば、ID列や自由入力の文字列列では、ほとんど同じ値が出てこないことがあります。その場合、集計しても見づらくなることがあります。</p>
<p>そんなときは、上位だけ確認する方法が便利です。</p>
<p>print(df[&#8220;member_rank&#8221;].value_counts(dropna=False).head())</p>
<p><strong>この考え方のポイント</strong></p>
<p>value_counts() はカテゴリ列にはとても向いていますが、ほぼすべて違う値が入っている列では、結果が長すぎて役立ちにくいことがあります。そのような場合は head() で上位だけを見る、あるいは別の列を集計対象にする、といった工夫が必要です。</p>

<h2><span id="toc23">よくある間違い</span></h2>

<h3><span id="toc24">NaN が表示されないのはおかしいと思ってしまう</span></h3>
<p>これはバグではありません。value_counts() はデフォルトで NaN を除外します。df[&#8220;member_rank&#8221;].value_counts(dropna=False)と書けば、NaN も数えられます。</p>

<h3><span id="toc25">割合が 0〜1 の小数で返ってきて戸惑う</span></h3>
<p>normalize=True は割合を返しますが、50% ではなく 0.5 のように返ってきます。(df[&#8220;member_rank&#8221;].value_counts(normalize=True) * 100).round(1)のように書くと、見やすくなります。</p>

<h3><span id="toc26">表記ゆれに気づかず、そのまま集計してしまう</span></h3>
<p>Silver と &#8221; Silver &#8220;、Bronze と bronze のように、見た目は近くても別の値として集計されます。そのため、件数を見るときは、<strong>本当に同じカテゴリとして扱ってよいか</strong>を意識することが大切です。</p>

<h2><span id="toc27">ワンポイント</span></h2>
<p>value_counts() は、head()、info()、describe() と並んで、<strong>データを読み込んだ直後に確認したい基本操作</strong>の1つです。</p>
<p>head() で先頭行を見る
info() で型と欠損を見る
value_counts() でカテゴリの分布を見る
という流れで確認すると、データの全体像をかなりつかみやすくなります。</p>
<p>つまり、value_counts() は「あとで使う関数」ではなく、<strong>最初に使う確認用メソッド</strong>として覚えておくと実務でも役立ちます。</p>

<h2><span id="toc28">まとめ</span></h2>
<p>value_counts() は、<strong>列の値ごとの出現回数をすばやく集計できる便利なメソッド</strong>です。</p>
<p>基本の形はとてもシンプルです。</p>
<p>df[&#8220;列名&#8221;].value_counts()
さらに、</p>
<ul>
<li>割合を出したい → normalize=True</li>
<li>欠損値も含めたい → dropna=False</li>
<li>少ない順に並べたい → ascending=True
を組み合わせることで、より実用的に使えます。</li>
</ul>
<p>また、単なる件数集計だけでなく、</p>
<ul>
<li>カテゴリの偏り確認</li>
<li>欠損値の確認</li>
<li>表記ゆれの発見</li>
<li>可視化前の下準備</li>
</ul>
<p>にも役立ちます。</p>
<p>Pandasでデータを読み込んだら、head() や info() とあわせて、ぜひ value_counts() も使ってみてください。</p>

<style>
.colab-article { color:#222; line-height:1.8; font-size:16px; }
.colab-article h1, .colab-article h2, .colab-article h3, .colab-article h4, .colab-article h5, .colab-article h6 { line-height:1.4; margin:1.6em 0 0.7em; }
.colab-article p { margin:0 0 1.1em; }
.colab-article ul, .colab-article ol { margin:0 0 1.1em 1.4em; }
.colab-article li { margin:0.3em 0; }
.colab-article code:not(pre code) { background:#f5f5f5; padding:0.15em 0.4em; border-radius:4px; font-size:0.95em; }
.colab-article pre[class*="language-"] { margin:1.2em 0; border-radius:8px; overflow:auto; }
.colab-article .output-block { background:#fafafa; border:1px solid #e5e7eb; padding:14px 16px; border-radius:8px; overflow:auto; white-space:pre; line-height:1.6; }
.colab-article .table-scroll { overflow-x:auto; -webkit-overflow-scrolling:touch; margin:1.2em 0; }
.colab-article figure.wp-block-table { margin:0; }
.colab-article table.wp-block-table { border-collapse:collapse; width:auto; max-width:none; table-layout:auto; }
.colab-article table.wp-block-table th, .colab-article table.wp-block-table td { border:1px solid #d1d5db; padding:8px 12px; white-space:nowrap; text-align:left; vertical-align:top; }
.colab-article table.wp-block-table th { background:#f3f4f6; }
.colab-article .image-block { margin:1.2em 0; }
.colab-article .image-block img { max-width:100%; height:auto; display:block; }
</style>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/themes/prism-tomorrow.min.css" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/plugins/toolbar/prism-toolbar.min.css" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/prism.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/components/prism-python.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/plugins/toolbar/prism-toolbar.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/plugins/copy-to-clipboard/prism-copy-to-clipboard.min.js"></script>


<!-- ▼▼▼ 関連記事ボックス 共通スタイル（カテゴリ）▼▼▼ -->
<style> .related-box { border: 2px solid #0073aa; border-radius: 10px; padding: 1em 1.2em; margin-top: 2em; background: #f8faff; } .related-box h3 { margin-top: 0; color: #0073aa; } .related-box ul { list-style-type: none; margin: 0; padding: 0; } .related-box li { margin: 0.4em 0; } .related-box a { text-decoration: none; color: #333; } .related-box a:hover { text-decoration: underline; color: #0073aa; } </style> <div class="related-box"> <h3><span id="toc29">関連記事</span></h3> <ul> 
<ul>
  <li><a href="https://pythondatalab.com/category/pandas/basic/">◀ Pandas 基礎</a></li>
  <li><a href="https://pythondatalab.com/category/pandas/preprocessing/">◀ Pandas 抽出・前処理</a></li>
  <li><a href="https://pythondatalab.com/category/pandas/aggregation/">◀ Pandas 集計・変形</a></li>
  <li><a href="https://pythondatalab.com/category/pandas/visualization/">▶ Matplotlib　可視化</a></li> </ul> </div>
<!-- ▼▼▼ 関連記事ボックス 共通スタイル（カテゴリ）終了▼▼▼ -->

<p style="text-align: center; margin-top: 2em;"><a href="#top">▲ ページトップへ戻る</a></p>

</div>


<div id="rank-math-faq" class="rank-math-block">
<div class="rank-math-list ">
<div id="faq-question-1774176973991" class="rank-math-list-item">
<h3 class="rank-math-question "><span id="toc30">value_counts() とは何ですか？</span></h3>
<div class="rank-math-answer ">

<p>Seriesに含まれる値ごとの出現回数を数えるメソッドです。1列のカテゴリ分布を確認するときによく使います。</p>

</div>
</div>
<div id="faq-question-1774176997535" class="rank-math-list-item">
<h3 class="rank-math-question "><span id="toc31">割合を表示するにはどうすればよいですか？</span></h3>
<div class="rank-math-answer ">

<p><code>normalize=True</code> を指定します。<br />df[&#8220;member_rank&#8221;].value_counts(normalize=True)</p>

</div>
</div>
<div id="faq-question-1774177030143" class="rank-math-list-item">
<h3 class="rank-math-question "><span id="toc32">欠損値も数えられますか？</span></h3>
<div class="rank-math-answer ">

<p>はい。<code>dropna=False</code> を指定すると、NaN も件数に含められます。<br />df[&#8220;member_rank&#8221;].value_counts(dropna=False)</p>

</div>
</div>
<div id="faq-question-1774177055790" class="rank-math-list-item">
<h3 class="rank-math-question "><span id="toc33">groupby().size() との違いは何ですか？</span></h3>
<div class="rank-math-answer ">

<p><code>value_counts()</code> は1列の出現回数を手軽に数えるのに向いています。<br />一方、<code>groupby().size()</code> は複数列の組み合わせ集計など、より柔軟な集計に向いています。</p>

</div>
</div>
</div>
</div><p>&lt;p&gt;The post <a rel="nofollow" href="https://pythondatalab.com/pandas-value-counts/">pandas value_counts()の使い方｜件数集計・割合表示・欠損値の数え方を解説</a> first appeared on <a rel="nofollow" href="https://pythondatalab.com">Python Data Lab（Pythonデータラボ）</a>.&lt;/p&gt;</p>
]]></content:encoded>
					
					<wfw:commentRss>https://pythondatalab.com/pandas-value-counts/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>pandas describe()の使い方｜統計量の意味・include=&#8217;all&#8217;・info()との違いを解説</title>
		<link>https://pythondatalab.com/pandas-info-describe/</link>
					<comments>https://pythondatalab.com/pandas-info-describe/#respond</comments>
		
		<dc:creator><![CDATA[coin_collector]]></dc:creator>
		<pubDate>Sun, 13 Apr 2025 14:06:00 +0000</pubDate>
				<category><![CDATA[基礎]]></category>
		<guid isPermaLink="false"></guid>

					<description><![CDATA[<p>pandasのdescribe()で出力されるcount・mean・std・min・25%・50%・75%・maxの意味を初心者向けに解説。数値列・文字列列の違い、include='all'、include/exclude、info()との使い分けまで、出力例つきで整理します。</p>
<p>&lt;p&gt;The post <a rel="nofollow" href="https://pythondatalab.com/pandas-info-describe/">pandas describe()の使い方｜統計量の意味・include=&#8217;all&#8217;・info()との違いを解説</a> first appeared on <a rel="nofollow" href="https://pythondatalab.com">Python Data Lab（Pythonデータラボ）</a>.&lt;/p&gt;</p>
]]></description>
										<content:encoded><![CDATA[
<div class="colab-article">

<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/prismjs/themes/prism-tomorrow.min.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/prismjs/plugins/toolbar/prism-toolbar.min.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/prismjs/plugins/line-numbers/prism-line-numbers.min.css">

<script src="https://cdn.jsdelivr.net/npm/prismjs/components/prism-core.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/prismjs/components/prism-clike.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/prismjs/components/prism-python.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/prismjs/plugins/line-numbers/prism-line-numbers.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/prismjs/plugins/toolbar/prism-toolbar.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/prismjs/plugins/copy-to-clipboard/prism-copy-to-clipboard.min.js"></script>

<style>
  .colab-article {
    max-width: 100%;
  }
  .colab-article pre[class*="language-"] {
    margin: 0 !important;
    padding: 1em;
    overflow-x: auto;
  }
  .colab-article pre.colab-output {
    margin: 0 !important;
    padding: 0.8em 1em;
    background: #f5f5f5;
    overflow-x: auto;
    border-radius: 4px;
  }
  .colab-article pre.colab-output code {
    background: transparent;
    padding: 0;
    white-space: pre;
  }
  .colab-article code {
    font-family: Consolas, Monaco, 'Courier New', monospace;
  }
  .colab-article :not(pre) > code {
    background: #f5f5f5;
    padding: 0.1em 0.3em;
    border-radius: 3px;
  }
  .colab-article .pdl-table-scroll {
    overflow-x: auto;
    max-width: 100%;
    margin: 0.8em 0;
  }
  .colab-article table.wp-block-table {
    width: auto;
    border-collapse: collapse;
  }
  .colab-article table.wp-block-table th,
  .colab-article table.wp-block-table td {
    border: 1px solid #ddd;
  }
  .colab-article figure.colab-figure {
    margin: 1em 0;
  }
  .colab-article figure.colab-figure img {
    max-width: 100%;
    height: auto;
  }
</style>

<script>Prism.highlightAll();</script>




<p><code>pandas</code> の <code>describe()</code> は、DataFrameやSeriesの<strong>要約統計量をまとめて確認するメソッド</strong>です。</p>
<p>数値列に対して <code>df.describe()</code> を実行すると、<code>count</code>、<code>mean</code>、<code>std</code>、<code>min</code>、<code>25%</code>、<code>50%</code>、<code>75%</code>、<code>max</code> が一覧で表示されます。</p>
<p>つまり、<code>describe()</code> は、<strong>データの件数・平均・ばらつき・最小値・最大値・中央値などを一度に確認したいとき</strong>に使います。</p>
<p>CSVやExcelファイルを読み込んだあと、いきなりグラフ化や機械学習に進むのではなく、まず <code>describe()</code> で数値列の特徴を確認しておくと、外れ値・極端な値・欠損値の影響に気づきやすくなります。</p>
<p>この記事では、<code>describe()</code> の基本的な使い方、出力される統計量の意味、<code>include='all'</code>、<code>include</code> / <code>exclude</code>、<code>info()</code> との違いまで、初心者向けに出力例つきで解説します。</p>


<p><strong>この記事でわかること</strong></p>
<p>この記事では、次の内容を扱います。</p>
<ul>
<li><code>df.describe()</code> の基本的な使い方</li>
<li><code>count</code>、<code>mean</code>、<code>std</code>、<code>min</code>、<code>25%</code>、<code>50%</code>、<code>75%</code>、<code>max</code> の意味</li>
<li>数値列と文字列列で <code>describe()</code> の出力がどう変わるか</li>
<li><code>include='all'</code> で全列を確認する方法</li>
<li>日付列で <code>describe()</code> を使った場合の見方</li>
<li><code>include</code> / <code>exclude</code> で対象列を指定する方法</li>
<li><code>percentiles</code> で表示する分位点を変更する方法</li>
<li><code>Series.describe()</code> と <code>DataFrame.describe()</code> の違い</li>
<li><code>describe()</code> と <code>info()</code> の使い分け</li>
<li><code>describe()</code> と <code>mean()</code>、<code>std()</code>、<code>quantile()</code> の関係</li>
</ul>



  <div id="toc" class="toc tnt-number toc-center tnt-number border-element"><input type="checkbox" class="toc-checkbox" id="toc-checkbox-2" checked><label class="toc-title" for="toc-checkbox-2">目次</label>
    <div class="toc-content">
    <ol class="toc-list open"><li><a href="#toc1" tabindex="0">pandas describe()とは？要約統計量をまとめて確認するメソッド</a></li><li><a href="#toc2" tabindex="0">サンプルデータを用意する</a></li><li><a href="#toc3" tabindex="0">df.describe()の基本的な使い方</a></li><li><a href="#toc4" tabindex="0">describe()で出力される項目の意味</a><ol><li><a href="#toc5" tabindex="0">count：欠損値を除いた件数</a></li><li><a href="#toc6" tabindex="0">mean：平均値</a></li><li><a href="#toc7" tabindex="0">std：標準偏差</a></li><li><a href="#toc8" tabindex="0">min / max：最小値・最大値</a></li><li><a href="#toc9" tabindex="0">25% / 50% / 75%：四分位数・中央値</a></li></ol></li><li><a href="#toc10" tabindex="0">数値列と文字列列でdescribe()の出力はどう変わるか</a></li><li><a href="#toc11" tabindex="0">日付列をdescribe()で確認する場合</a></li><li><a href="#toc12" tabindex="0">describe()の便利な引数</a><ol><li><a href="#toc13" tabindex="0">include=&#8217;all&#8217;ですべての列を確認する</a></li><li><a href="#toc14" tabindex="0">includeで対象列を指定する</a></li><li><a href="#toc15" tabindex="0">percentilesで表示する分位点を変更する</a></li></ol></li><li><a href="#toc16" tabindex="0">Series.describe()とDataFrame.describe()の違い</a></li><li><a href="#toc17" tabindex="0">describe()とinfo()の違い</a></li><li><a href="#toc18" tabindex="0">describe()とmean()・std()・quantile()の違い</a></li><li><a href="#toc19" tabindex="0">describe()で外れ値や極端な値に気づく例</a></li><li><a href="#toc20" tabindex="0">欠損値がある場合のdescribe()の見方</a></li><li><a href="#toc21" tabindex="0">よくあるミス</a><ol><li><a href="#toc22" tabindex="0">数値列しか表示されないと思って混乱する</a></li><li><a href="#toc23" tabindex="0">countを行数だと思ってしまう</a></li><li><a href="#toc24" tabindex="0">50%を平均値だと思ってしまう</a></li><li><a href="#toc25" tabindex="0">stdの意味がわからないまま読み飛ばす</a></li><li><a href="#toc26" tabindex="0">include=&#8217;all&#8217;でNaNが出て不安になる</a></li></ol></li><li><a href="#toc27" tabindex="0">実務でのおすすめ確認手順</a></li><li><a href="#toc28" tabindex="0">まとめ</a></li><li><a href="#toc29" tabindex="0">公式ドキュメント</a></li><li><a href="#toc30" tabindex="0">次に読みたい関連記事</a><ol><li><a href="#toc31" tabindex="0"> カテゴリから探す</a></li></ol></li></ol>
    </div>
  </div>

<h2><span id="toc1">pandas describe()とは？要約統計量をまとめて確認するメソッド</span></h2>
<p><code>describe()</code> は、DataFrameやSeriesの概要を数値で確認するためのメソッドです。</p>
<p>特に数値列に対して使うと、平均値、標準偏差、最小値、最大値、中央値などをまとめて確認できます。</p>
<p>たとえば、売上データを読み込んだあとに、</p>
<ul>
<li>売上の平均はいくらか</li>
<li>最小値や最大値に極端な値がないか</li>
<li>中央値と平均値に大きな差がないか</li>
<li>データ件数が列ごとにそろっているか</li>
</ul>
<p>を確認したいときに便利です。</p>
<p>最初に覚えるなら、次のように考えるとわかりやすいです。</p>
<div class="pdl-table-scroll" style="overflow-x: auto; max-width: 100%;"><table class="wp-block-table" style="width: auto; border-collapse: collapse;">
<thead>
<tr>
<th style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">メソッド</th>
<th style="white-space: nowrap; padding: 0.2em 0.4em;">役割</th>
</tr>
</thead>
<tbody>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;"><code>df.describe()</code></td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">数値列の統計量をまとめて確認する</td>
</tr>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;"><code>df.describe(include='all')</code></td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">数値列・文字列列を含めて確認する</td>
</tr>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;"><code>df.info()</code></td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">列名・データ型・欠損値・メモリ使用量を確認する</td>
</tr>
</tbody>
</table></div>


<h2><span id="toc2">サンプルデータを用意する</span></h2>
<p>ここでは、売上データを例にします。</p>
<p><code>商品</code>、<code>カテゴリ</code>、<code>店舗</code> のような文字列列と、<code>単価</code>、<code>数量</code>、<code>売上</code>、<code>満足度</code> のような数値列を含むDataFrameを使います。</p>
<p>実際の分析ではCSVやExcelから読み込むことが多いですが、ここでは説明をわかりやすくするために、コード上でDataFrameを作成します。</p>


<pre class="line-numbers"><code class="language-python">import pandas as pd

df = pd.DataFrame({
    "日付": pd.to_datetime([
        "2026-01-05", "2026-01-08", "2026-01-12", "2026-01-15",
        "2026-01-20", "2026-01-24", "2026-01-28", "2026-01-31"
    ]),
    "商品": ["ノートPC", "マウス", "キーボード", "モニター", "USBメモリ", "ノートPC", "マウス", "モニター"],
    "カテゴリ": ["PC", "周辺機器", "周辺機器", "周辺機器", "記録媒体", "PC", "周辺機器", "周辺機器"],
    "店舗": ["東京", "東京", "大阪", "大阪", "名古屋", "東京", "名古屋", "大阪"],
    "単価": [120000, 3000, 8000, 32000, 2500, 115000, 2800, 35000],
    "数量": [1, 5, 3, 2, 10, 1, 4, 2],
    "売上": [120000, 15000, 24000, 64000, 25000, 115000, 11200, 70000],
    "満足度": [4.8, 4.2, 4.0, 4.5, 3.8, 4.7, 4.1, 4.4]
})

df</code></pre>

<div class="pdl-table-scroll" style="overflow-x: auto; max-width: 100%;">
<table class="wp-block-table" style="width: auto; border-collapse: collapse;">
<thead>
<tr>
<th style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;"></th>
<th style="white-space: nowrap; padding: 0.2em 0.4em;">日付</th>
<th style="white-space: nowrap; padding: 0.2em 0.4em;">商品</th>
<th style="white-space: nowrap; padding: 0.2em 0.4em;">カテゴリ</th>
<th style="white-space: nowrap; padding: 0.2em 0.4em;">店舗</th>
<th style="white-space: nowrap; padding: 0.2em 0.4em;">単価</th>
<th style="white-space: nowrap; padding: 0.2em 0.4em;">数量</th>
<th style="white-space: nowrap; padding: 0.2em 0.4em;">売上</th>
<th style="white-space: nowrap; padding: 0.2em 0.4em;">満足度</th>
</tr>
</thead>
<tbody>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">0</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">2026-01-05 00:00:00</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">ノートPC</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">PC</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">東京</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">120000</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">1</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">120000</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">4.8</td>
</tr>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">1</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">2026-01-08 00:00:00</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">マウス</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">周辺機器</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">東京</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">3000</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">5</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">15000</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">4.2</td>
</tr>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">2</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">2026-01-12 00:00:00</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">キーボード</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">周辺機器</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">大阪</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">8000</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">3</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">24000</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">4</td>
</tr>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">3</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">2026-01-15 00:00:00</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">モニター</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">周辺機器</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">大阪</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">32000</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">2</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">64000</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">4.5</td>
</tr>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">4</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">2026-01-20 00:00:00</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">USBメモリ</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">記録媒体</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">名古屋</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">2500</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">10</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">25000</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">3.8</td>
</tr>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">5</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">2026-01-24 00:00:00</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">ノートPC</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">PC</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">東京</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">115000</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">1</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">115000</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">4.7</td>
</tr>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">6</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">2026-01-28 00:00:00</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">マウス</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">周辺機器</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">名古屋</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">2800</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">4</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">11200</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">4.1</td>
</tr>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">7</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">2026-01-31 00:00:00</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">モニター</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">周辺機器</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">大阪</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">35000</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">2</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">70000</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">4.4</td>
</tr>
</tbody>
</table>
</div>

<p>このDataFrameには、日付列、文字列列、数値列が混在しています。</p>
<p><code>describe()</code> は、標準では数値列を中心に統計量を表示します。必要に応じて <code>include</code> や <code>exclude</code> を使うと、文字列列や日付列も確認できます。</p>


<h2><span id="toc3">df.describe()の基本的な使い方</span></h2>
<p><code>describe()</code> の基本形は次のとおりです。</p>
<pre class="line-numbers"><code class="language-python">df.describe()
</code></pre>
<p>まずは、そのまま実行してみます。</p>


<pre class="line-numbers"><code class="language-python">df.describe()</code></pre>

<div class="pdl-table-scroll" style="overflow-x: auto; max-width: 100%;">
<table class="wp-block-table" style="width: auto; border-collapse: collapse;">
<thead>
<tr>
<th style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;"></th>
<th style="white-space: nowrap; padding: 0.2em 0.4em;">日付</th>
<th style="white-space: nowrap; padding: 0.2em 0.4em;">単価</th>
<th style="white-space: nowrap; padding: 0.2em 0.4em;">数量</th>
<th style="white-space: nowrap; padding: 0.2em 0.4em;">売上</th>
<th style="white-space: nowrap; padding: 0.2em 0.4em;">満足度</th>
</tr>
</thead>
<tbody>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">count</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">8</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">8</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">8</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">8</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">8</td>
</tr>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">mean</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">2026-01-17 21:00:00</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">39787.5</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">3.5</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">55525</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">4.3125</td>
</tr>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">min</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">2026-01-05 00:00:00</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">2500</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">1</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">11200</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">3.8</td>
</tr>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">25%</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">2026-01-11 00:00:00</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">2950</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">1.75</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">21750</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">4.075</td>
</tr>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">50%</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">2026-01-17 12:00:00</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">20000</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">2.5</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">44500</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">4.3</td>
</tr>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">75%</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">2026-01-25 00:00:00</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">55000</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">4.25</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">81250</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">4.55</td>
</tr>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">max</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">2026-01-31 00:00:00</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">120000</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">10</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">120000</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">4.8</td>
</tr>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">std</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">NaN</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">49708.8</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">2.9761</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">43928.9</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">0.34821</td>
</tr>
</tbody>
</table>
</div>

<p><code>df.describe()</code> を実行すると、標準では数値列だけが対象になります。</p>
<p>今回の例では、<code>単価</code>、<code>数量</code>、<code>売上</code>、<code>満足度</code> について、件数、平均、標準偏差、最小値、四分位数、最大値が表示されます。</p>
<p>ここで特に大事なのは、<strong>出力された数字をそのまま眺めるだけでなく、各項目の意味を理解すること</strong>です。</p>


<h2><span id="toc4">describe()で出力される項目の意味</span></h2>
<p><code>describe()</code> の出力で最初に押さえたい項目は、次の8つです。</p>
<div class="pdl-table-scroll" style="overflow-x: auto; max-width: 100%;"><table class="wp-block-table" style="width: auto; border-collapse: collapse;">
<thead>
<tr>
<th style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">項目</th>
<th style="white-space: nowrap; padding: 0.2em 0.4em;">意味</th>
<th style="white-space: nowrap; padding: 0.2em 0.4em;">初心者向けの見方</th>
</tr>
</thead>
<tbody>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;"><code>count</code></td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">欠損値を除いた件数</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">データが何件あるか</td>
</tr>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;"><code>mean</code></td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">平均値</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">値のだいたいの中心</td>
</tr>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;"><code>std</code></td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">標準偏差</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">値のばらつき</td>
</tr>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;"><code>min</code></td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">最小値</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">一番小さい値</td>
</tr>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;"><code>25%</code></td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">第1四分位数</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">下から25%の位置</td>
</tr>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;"><code>50%</code></td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">中央値</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">真ん中の値</td>
</tr>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;"><code>75%</code></td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">第3四分位数</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">下から75%の位置</td>
</tr>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;"><code>max</code></td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">最大値</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">一番大きい値</td>
</tr>
</tbody>
</table></div>
<p>それぞれを順番に見ていきます。</p>


<h3><span id="toc5">count：欠損値を除いた件数</span></h3>
<p><code>count</code> は、欠損値を除いたデータの件数です。</p>
<p>たとえば、8行のデータがあり、ある列に欠損値がなければ <code>count</code> は8になります。</p>
<p>もし列によって <code>count</code> の値が違う場合は、欠損値が含まれている可能性があります。</p>


<pre class="line-numbers"><code class="language-python">df.describe().loc["count"]</code></pre>

<div class="pdl-table-scroll" style="overflow-x: auto; max-width: 100%;">
<table class="wp-block-table" style="width: auto; border-collapse: collapse;">
<thead>
<tr>
<th style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;"></th>
<th style="white-space: nowrap; padding: 0.2em 0.4em;">count</th>
</tr>
</thead>
<tbody>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">日付</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">8</td>
</tr>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">単価</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">8</td>
</tr>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">数量</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">8</td>
</tr>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">売上</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">8</td>
</tr>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">満足度</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">8</td>
</tr>
</tbody>
</table>
</div>

<p><code>count</code> は、単なる行数ではなく、<strong>欠損値を除いた件数</strong>です。</p>
<p>欠損値の確認を詳しく行う場合は、<code>info()</code> や <code>isnull().sum()</code> と組み合わせて確認します。</p>


<h3><span id="toc6">mean：平均値</span></h3>
<p><code>mean</code> は平均値です。</p>
<p>売上データであれば、売上の平均、単価の平均、満足度の平均などを確認できます。</p>


<pre class="line-numbers"><code class="language-python">df.describe().loc["mean"]</code></pre>

<div class="pdl-table-scroll" style="overflow-x: auto; max-width: 100%;">
<table class="wp-block-table" style="width: auto; border-collapse: collapse;">
<thead>
<tr>
<th style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;"></th>
<th style="white-space: nowrap; padding: 0.2em 0.4em;">mean</th>
</tr>
</thead>
<tbody>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">日付</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">2026-01-17 21:00:00</td>
</tr>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">単価</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">39787.5</td>
</tr>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">数量</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">3.5</td>
</tr>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">売上</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">55525</td>
</tr>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">満足度</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">4.3125</td>
</tr>
</tbody>
</table>
</div>

<p>平均値は便利ですが、極端に大きい値や小さい値の影響を受けやすい点に注意が必要です。</p>
<p>たとえば、一部の商品だけ売上が非常に大きい場合、平均値だけを見ると全体像を誤解することがあります。</p>
<p>そのため、平均値だけでなく、<code>50%</code> の中央値や <code>min</code>、<code>max</code> も一緒に確認することが大切です。</p>


<h3><span id="toc7">std：標準偏差</span></h3>
<p><code>std</code> は標準偏差です。</p>
<p>標準偏差は、値が平均値の周りにどれくらい散らばっているかを表します。</p>
<p>初心者のうちは、次のように考えるとわかりやすいです。</p>
<div class="pdl-table-scroll" style="overflow-x: auto; max-width: 100%;"><table class="wp-block-table" style="width: auto; border-collapse: collapse;">
<thead>
<tr>
<th style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;"><code>std</code> の状態</th>
<th style="white-space: nowrap; padding: 0.2em 0.4em;">見方</th>
</tr>
</thead>
<tbody>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">小さい</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">値が平均付近に集まっている</td>
</tr>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">大きい</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">値のばらつきが大きい</td>
</tr>
</tbody>
</table></div>
<p>たとえば、売上の <code>std</code> が大きい場合、商品や店舗によって売上に大きな差がある可能性があります。</p>


<pre class="line-numbers"><code class="language-python">df.describe().loc["std"]</code></pre>

<div class="pdl-table-scroll" style="overflow-x: auto; max-width: 100%;">
<table class="wp-block-table" style="width: auto; border-collapse: collapse;">
<thead>
<tr>
<th style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;"></th>
<th style="white-space: nowrap; padding: 0.2em 0.4em;">std</th>
</tr>
</thead>
<tbody>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">日付</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">NaN</td>
</tr>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">単価</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">49708.8</td>
</tr>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">数量</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">2.9761</td>
</tr>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">売上</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">43928.9</td>
</tr>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">満足度</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">0.34821</td>
</tr>
</tbody>
</table>
</div>

<p>標準偏差は、平均値とセットで見ると理解しやすくなります。</p>
<p>平均値が同じでも、標準偏差が大きければ値のばらつきが大きく、標準偏差が小さければ値が比較的まとまっていると考えられます。</p>


<h3><span id="toc8">min / max：最小値・最大値</span></h3>
<p><code>min</code> は最小値、<code>max</code> は最大値です。</p>
<p>外れ値や入力ミスを見つけるときに役立ちます。</p>


<pre class="line-numbers"><code class="language-python">df.describe().loc[["min", "max"]]</code></pre>

<div class="pdl-table-scroll" style="overflow-x: auto; max-width: 100%;">
<table class="wp-block-table" style="width: auto; border-collapse: collapse;">
<thead>
<tr>
<th style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;"></th>
<th style="white-space: nowrap; padding: 0.2em 0.4em;">日付</th>
<th style="white-space: nowrap; padding: 0.2em 0.4em;">単価</th>
<th style="white-space: nowrap; padding: 0.2em 0.4em;">数量</th>
<th style="white-space: nowrap; padding: 0.2em 0.4em;">売上</th>
<th style="white-space: nowrap; padding: 0.2em 0.4em;">満足度</th>
</tr>
</thead>
<tbody>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">min</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">2026-01-05 00:00:00</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">2500</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">1</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">11200</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">3.8</td>
</tr>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">max</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">2026-01-31 00:00:00</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">120000</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">10</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">120000</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">4.8</td>
</tr>
</tbody>
</table>
</div>

<p>たとえば、年齢データで <code>max</code> が300になっていたり、売上データで <code>min</code> がマイナスになっていたりすると、入力ミスや特殊なデータの可能性があります。</p>
<p><code>min</code> と <code>max</code> は、データの範囲をざっくり確認するために重要です。</p>


<h3><span id="toc9">25% / 50% / 75%：四分位数・中央値</span></h3>
<p><code>25%</code>、<code>50%</code>、<code>75%</code> は、データを小さい順に並べたときの位置を表します。</p>
<div class="pdl-table-scroll" style="overflow-x: auto; max-width: 100%;"><table class="wp-block-table" style="width: auto; border-collapse: collapse;">
<thead>
<tr>
<th style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">項目</th>
<th style="white-space: nowrap; padding: 0.2em 0.4em;">意味</th>
</tr>
</thead>
<tbody>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;"><code>25%</code></td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">下から25%の位置の値</td>
</tr>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;"><code>50%</code></td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">下から50%の位置の値。中央値</td>
</tr>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;"><code>75%</code></td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">下から75%の位置の値</td>
</tr>
</tbody>
</table></div>
<p>特に <code>50%</code> は中央値です。</p>
<p>平均値と中央値を比べると、データの偏りに気づきやすくなります。</p>


<pre class="line-numbers"><code class="language-python">df.describe().loc[["25%", "50%", "75%"]]</code></pre>

<div class="pdl-table-scroll" style="overflow-x: auto; max-width: 100%;">
<table class="wp-block-table" style="width: auto; border-collapse: collapse;">
<thead>
<tr>
<th style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;"></th>
<th style="white-space: nowrap; padding: 0.2em 0.4em;">日付</th>
<th style="white-space: nowrap; padding: 0.2em 0.4em;">単価</th>
<th style="white-space: nowrap; padding: 0.2em 0.4em;">数量</th>
<th style="white-space: nowrap; padding: 0.2em 0.4em;">売上</th>
<th style="white-space: nowrap; padding: 0.2em 0.4em;">満足度</th>
</tr>
</thead>
<tbody>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">25%</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">2026-01-11 00:00:00</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">2950</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">1.75</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">21750</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">4.075</td>
</tr>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">50%</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">2026-01-17 12:00:00</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">20000</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">2.5</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">44500</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">4.3</td>
</tr>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">75%</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">2026-01-25 00:00:00</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">55000</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">4.25</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">81250</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">4.55</td>
</tr>
</tbody>
</table>
</div>

<p>たとえば、平均値が中央値よりかなり大きい場合、一部に大きな値が含まれている可能性があります。</p>
<p>売上データでは、一部の高額商品や大口注文が平均値を押し上げることがあります。</p>


<h2><span id="toc10">数値列と文字列列でdescribe()の出力はどう変わるか</span></h2>
<p><code>describe()</code> は、対象列のデータ型によって出力される項目が変わります。</p>
<p>数値列では、平均値や標準偏差などが表示されます。</p>
<p>一方、文字列列では、<code>unique</code>、<code>top</code>、<code>freq</code> などが表示されます。</p>
<p>まず、数値列だけを対象にした場合を確認します。</p>


<pre class="line-numbers"><code class="language-python">df[["単価", "数量", "売上", "満足度"]].describe()</code></pre>

<div class="pdl-table-scroll" style="overflow-x: auto; max-width: 100%;">
<table class="wp-block-table" style="width: auto; border-collapse: collapse;">
<thead>
<tr>
<th style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;"></th>
<th style="white-space: nowrap; padding: 0.2em 0.4em;">単価</th>
<th style="white-space: nowrap; padding: 0.2em 0.4em;">数量</th>
<th style="white-space: nowrap; padding: 0.2em 0.4em;">売上</th>
<th style="white-space: nowrap; padding: 0.2em 0.4em;">満足度</th>
</tr>
</thead>
<tbody>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">count</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">8</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">8</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">8</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">8</td>
</tr>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">mean</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">39787.5</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">3.5</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">55525</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">4.3125</td>
</tr>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">std</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">49708.8</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">2.9761</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">43928.9</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">0.34821</td>
</tr>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">min</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">2500</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">1</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">11200</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">3.8</td>
</tr>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">25%</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">2950</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">1.75</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">21750</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">4.075</td>
</tr>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">50%</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">20000</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">2.5</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">44500</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">4.3</td>
</tr>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">75%</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">55000</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">4.25</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">81250</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">4.55</td>
</tr>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">max</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">120000</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">10</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">120000</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">4.8</td>
</tr>
</tbody>
</table>
</div>

<p>次に、文字列列だけを対象にして <code>describe()</code> を実行します。</p>


<pre class="line-numbers"><code class="language-python">df[["商品", "カテゴリ", "店舗"]].describe()</code></pre>

<div class="pdl-table-scroll" style="overflow-x: auto; max-width: 100%;">
<table class="wp-block-table" style="width: auto; border-collapse: collapse;">
<thead>
<tr>
<th style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;"></th>
<th style="white-space: nowrap; padding: 0.2em 0.4em;">商品</th>
<th style="white-space: nowrap; padding: 0.2em 0.4em;">カテゴリ</th>
<th style="white-space: nowrap; padding: 0.2em 0.4em;">店舗</th>
</tr>
</thead>
<tbody>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">count</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">8</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">8</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">8</td>
</tr>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">unique</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">5</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">3</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">3</td>
</tr>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">top</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">ノートPC</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">周辺機器</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">東京</td>
</tr>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">freq</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">2</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">5</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">3</td>
</tr>
</tbody>
</table>
</div>

<p>文字列列では、数値列とは違う項目が表示されます。</p>
<div class="pdl-table-scroll" style="overflow-x: auto; max-width: 100%;"><table class="wp-block-table" style="width: auto; border-collapse: collapse;">
<thead>
<tr>
<th style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">項目</th>
<th style="white-space: nowrap; padding: 0.2em 0.4em;">意味</th>
</tr>
</thead>
<tbody>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;"><code>count</code></td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">欠損値を除いた件数</td>
</tr>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;"><code>unique</code></td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">値の種類数</td>
</tr>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;"><code>top</code></td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">最も多く出現する値</td>
</tr>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;"><code>freq</code></td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;"><code>top</code> の出現回数</td>
</tr>
</tbody>
</table></div>
<p>たとえば、<code>カテゴリ</code> の <code>top</code> が「周辺機器」で、<code>freq</code> が多ければ、周辺機器カテゴリの商品が多いことがわかります。</p>
<p>このように、<code>describe()</code> は数値列だけでなく、文字列列の概要確認にも使えます。</p>


<h2><span id="toc11">日付列をdescribe()で確認する場合</span></h2>
<p><code>describe()</code> は、日付列に対しても使えます。</p>
<p>日付列を確認すると、最も古い日付、最も新しい日付、件数などを把握できます。</p>
<p>まず、<code>日付</code> 列だけを指定して <code>describe()</code> を実行してみます。</p>


<pre class="line-numbers"><code class="language-python">df["日付"].describe()</code></pre>

<div class="pdl-table-scroll" style="overflow-x: auto; max-width: 100%;">
<table class="wp-block-table" style="width: auto; border-collapse: collapse;">
<thead>
<tr>
<th style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;"></th>
<th style="white-space: nowrap; padding: 0.2em 0.4em;">日付</th>
</tr>
</thead>
<tbody>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">count</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">8</td>
</tr>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">mean</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">2026-01-17 21:00:00</td>
</tr>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">min</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">2026-01-05 00:00:00</td>
</tr>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">25%</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">2026-01-11 00:00:00</td>
</tr>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">50%</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">2026-01-17 12:00:00</td>
</tr>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">75%</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">2026-01-25 00:00:00</td>
</tr>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">max</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">2026-01-31 00:00:00</td>
</tr>
</tbody>
</table>
</div>

<p>日付列に対する <code>describe()</code> では、データの件数や最小日付、最大日付などを確認できます。</p>
<p>日付データを扱うときは、次のような確認に役立ちます。</p>
<div class="pdl-table-scroll" style="overflow-x: auto; max-width: 100%;"><table class="wp-block-table" style="width: auto; border-collapse: collapse;">
<thead>
<tr>
<th style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">見たいこと</th>
<th style="white-space: nowrap; padding: 0.2em 0.4em;">確認する項目</th>
</tr>
</thead>
<tbody>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">何件の日付データがあるか</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;"><code>count</code></td>
</tr>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">最も古い日付</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;"><code>min</code></td>
</tr>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">最も新しい日付</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;"><code>max</code></td>
</tr>
</tbody>
</table></div>
<p>売上データやアクセス解析データでは、集計対象の期間が想定どおりかを確認するために使えます。</p>
<p>ただし、日付列の詳しい集計には、<code>dt</code> アクセサや <code>resample()</code> を使うことも多いです。<code>describe()</code> は、日付データの範囲をざっくり確認する入口として使うと考えるとよいです。</p>


<h2><span id="toc12">describe()の便利な引数</span></h2>
<p>ここでは、<code>describe()</code> でよく使う引数を整理します。</p>
<p><code>include='all'</code>、<code>include</code>、<code>exclude</code>、<code>percentiles</code> を使えるようになると、確認したい列や分位点を指定しやすくなります。</p>
<h3><span id="toc13">include=&#8217;all&#8217;ですべての列を確認する</span></h3>
<p>標準の <code>df.describe()</code> は、基本的に数値列を対象にします。</p>
<p>数値列と文字列列をまとめて確認したい場合は、<code>include='all'</code> を指定します。</p>


<pre class="line-numbers"><code class="language-python">df.describe(include="all")</code></pre>

<div class="pdl-table-scroll" style="overflow-x: auto; max-width: 100%;">
<table class="wp-block-table" style="width: auto; border-collapse: collapse;">
<thead>
<tr>
<th style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;"></th>
<th style="white-space: nowrap; padding: 0.2em 0.4em;">日付</th>
<th style="white-space: nowrap; padding: 0.2em 0.4em;">商品</th>
<th style="white-space: nowrap; padding: 0.2em 0.4em;">カテゴリ</th>
<th style="white-space: nowrap; padding: 0.2em 0.4em;">店舗</th>
<th style="white-space: nowrap; padding: 0.2em 0.4em;">単価</th>
<th style="white-space: nowrap; padding: 0.2em 0.4em;">数量</th>
<th style="white-space: nowrap; padding: 0.2em 0.4em;">売上</th>
<th style="white-space: nowrap; padding: 0.2em 0.4em;">満足度</th>
</tr>
</thead>
<tbody>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">count</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">8</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">8</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">8</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">8</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">8</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">8</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">8</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">8</td>
</tr>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">unique</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">NaN</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">5</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">3</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">3</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">NaN</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">NaN</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">NaN</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">NaN</td>
</tr>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">top</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">NaN</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">ノートPC</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">周辺機器</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">東京</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">NaN</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">NaN</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">NaN</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">NaN</td>
</tr>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">freq</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">NaN</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">2</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">5</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">3</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">NaN</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">NaN</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">NaN</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">NaN</td>
</tr>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">mean</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">2026-01-17 21:00:00</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">NaN</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">NaN</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">NaN</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">39787.5</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">3.5</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">55525</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">4.3125</td>
</tr>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">min</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">2026-01-05 00:00:00</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">NaN</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">NaN</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">NaN</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">2500</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">1</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">11200</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">3.8</td>
</tr>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">25%</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">2026-01-11 00:00:00</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">NaN</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">NaN</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">NaN</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">2950</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">1.75</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">21750</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">4.075</td>
</tr>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">50%</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">2026-01-17 12:00:00</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">NaN</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">NaN</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">NaN</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">20000</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">2.5</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">44500</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">4.3</td>
</tr>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">75%</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">2026-01-25 00:00:00</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">NaN</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">NaN</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">NaN</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">55000</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">4.25</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">81250</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">4.55</td>
</tr>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">max</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">2026-01-31 00:00:00</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">NaN</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">NaN</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">NaN</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">120000</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">10</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">120000</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">4.8</td>
</tr>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">std</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">NaN</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">NaN</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">NaN</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">NaN</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">49708.8</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">2.9761</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">43928.9</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">0.34821</td>
</tr>
</tbody>
</table>
</div>

<p><code>include='all'</code> を指定すると、数値列と文字列列の両方が表示されます。</p>
<p>ただし、数値列にしか意味がない項目や、文字列列にしか意味がない項目があるため、該当しない部分は <code>NaN</code> と表示されます。</p>
<div class="pdl-table-scroll" style="overflow-x: auto; max-width: 100%;"><table class="wp-block-table" style="width: auto; border-collapse: collapse;">
<thead>
<tr>
<th style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">列の種類</th>
<th style="white-space: nowrap; padding: 0.2em 0.4em;">主に表示される項目</th>
</tr>
</thead>
<tbody>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">数値列</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;"><code>mean</code>、<code>std</code>、<code>min</code>、<code>25%</code>、<code>50%</code>、<code>75%</code>、<code>max</code></td>
</tr>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">文字列列</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;"><code>unique</code>、<code>top</code>、<code>freq</code></td>
</tr>
</tbody>
</table></div>
<p><code>include='all'</code> は、データ全体をざっと確認したいときに便利です。</p>


<h3><span id="toc14">includeで対象列を指定する</span></h3>
<p><code>describe()</code> では、<code>include</code> や <code>exclude</code> を使って対象にする列の種類を指定できます。</p>
<p>たとえば、文字列列だけを確認したい場合は、<code>include="object"</code> を使います。</p>


<pre class="line-numbers"><code class="language-python">df.describe(include="object")</code></pre>

<div class="pdl-table-scroll" style="overflow-x: auto; max-width: 100%;">
<table class="wp-block-table" style="width: auto; border-collapse: collapse;">
<thead>
<tr>
<th style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;"></th>
<th style="white-space: nowrap; padding: 0.2em 0.4em;">商品</th>
<th style="white-space: nowrap; padding: 0.2em 0.4em;">カテゴリ</th>
<th style="white-space: nowrap; padding: 0.2em 0.4em;">店舗</th>
</tr>
</thead>
<tbody>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">count</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">8</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">8</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">8</td>
</tr>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">unique</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">5</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">3</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">3</td>
</tr>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">top</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">ノートPC</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">周辺機器</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">東京</td>
</tr>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">freq</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">2</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">5</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">3</td>
</tr>
</tbody>
</table>
</div>

<p>数値列だけを明示的に確認したい場合は、<code>include="number"</code> を使います。</p>


<pre class="line-numbers"><code class="language-python">df.describe(include="number")</code></pre>

<div class="pdl-table-scroll" style="overflow-x: auto; max-width: 100%;">
<table class="wp-block-table" style="width: auto; border-collapse: collapse;">
<thead>
<tr>
<th style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;"></th>
<th style="white-space: nowrap; padding: 0.2em 0.4em;">単価</th>
<th style="white-space: nowrap; padding: 0.2em 0.4em;">数量</th>
<th style="white-space: nowrap; padding: 0.2em 0.4em;">売上</th>
<th style="white-space: nowrap; padding: 0.2em 0.4em;">満足度</th>
</tr>
</thead>
<tbody>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">count</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">8</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">8</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">8</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">8</td>
</tr>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">mean</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">39787.5</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">3.5</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">55525</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">4.3125</td>
</tr>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">std</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">49708.8</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">2.9761</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">43928.9</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">0.34821</td>
</tr>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">min</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">2500</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">1</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">11200</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">3.8</td>
</tr>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">25%</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">2950</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">1.75</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">21750</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">4.075</td>
</tr>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">50%</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">20000</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">2.5</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">44500</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">4.3</td>
</tr>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">75%</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">55000</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">4.25</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">81250</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">4.55</td>
</tr>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">max</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">120000</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">10</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">120000</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">4.8</td>
</tr>
</tbody>
</table>
</div>

<p>逆に、数値列を除外したい場合は、<code>exclude="number"</code> を使います。</p>


<pre class="line-numbers"><code class="language-python">df.describe(exclude="number")</code></pre>

<div class="pdl-table-scroll" style="overflow-x: auto; max-width: 100%;">
<table class="wp-block-table" style="width: auto; border-collapse: collapse;">
<thead>
<tr>
<th style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;"></th>
<th style="white-space: nowrap; padding: 0.2em 0.4em;">日付</th>
<th style="white-space: nowrap; padding: 0.2em 0.4em;">商品</th>
<th style="white-space: nowrap; padding: 0.2em 0.4em;">カテゴリ</th>
<th style="white-space: nowrap; padding: 0.2em 0.4em;">店舗</th>
</tr>
</thead>
<tbody>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">count</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">8</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">8</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">8</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">8</td>
</tr>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">unique</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">NaN</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">5</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">3</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">3</td>
</tr>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">top</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">NaN</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">ノートPC</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">周辺機器</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">東京</td>
</tr>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">freq</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">NaN</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">2</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">5</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">3</td>
</tr>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">mean</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">2026-01-17 21:00:00</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">NaT</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">NaT</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">NaT</td>
</tr>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">min</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">2026-01-05 00:00:00</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">NaT</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">NaT</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">NaT</td>
</tr>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">25%</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">2026-01-11 00:00:00</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">NaT</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">NaT</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">NaT</td>
</tr>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">50%</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">2026-01-17 12:00:00</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">NaT</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">NaT</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">NaT</td>
</tr>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">75%</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">2026-01-25 00:00:00</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">NaT</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">NaT</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">NaT</td>
</tr>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">max</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">2026-01-31 00:00:00</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">NaT</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">NaT</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">NaT</td>
</tr>
</tbody>
</table>
</div>

<p><code>include</code> と <code>exclude</code> は、列数が多いDataFrameで役立ちます。</p>
<p>たとえば、数十列あるデータで文字列列だけを確認したい場合、手作業で列名を選ぶよりも効率的です。</p>
<div class="pdl-table-scroll" style="overflow-x: auto; max-width: 100%;"><table class="wp-block-table" style="width: auto; border-collapse: collapse;">
<thead>
<tr>
<th style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">やりたいこと</th>
<th style="white-space: nowrap; padding: 0.2em 0.4em;">書き方</th>
</tr>
</thead>
<tbody>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">数値列だけ確認</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;"><code>df.describe(include="number")</code></td>
</tr>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">文字列列だけ確認</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;"><code>df.describe(include="object")</code></td>
</tr>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">すべての列を確認</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;"><code>df.describe(include="all")</code></td>
</tr>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">数値列を除外</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;"><code>df.describe(exclude="number")</code></td>
</tr>
</tbody>
</table></div>


<h3><span id="toc15">percentilesで表示する分位点を変更する</span></h3>
<p>標準の <code>describe()</code> では、<code>25%</code>、<code>50%</code>、<code>75%</code> が表示されます。</p>
<p>この分位点は、<code>percentiles</code> 引数で変更できます。</p>
<p>たとえば、10%、50%、90%の位置を確認したい場合は、次のように書きます。</p>


<pre class="line-numbers"><code class="language-python">df.describe(percentiles=[0.1, 0.5, 0.9])</code></pre>

<div class="pdl-table-scroll" style="overflow-x: auto; max-width: 100%;">
<table class="wp-block-table" style="width: auto; border-collapse: collapse;">
<thead>
<tr>
<th style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;"></th>
<th style="white-space: nowrap; padding: 0.2em 0.4em;">日付</th>
<th style="white-space: nowrap; padding: 0.2em 0.4em;">単価</th>
<th style="white-space: nowrap; padding: 0.2em 0.4em;">数量</th>
<th style="white-space: nowrap; padding: 0.2em 0.4em;">売上</th>
<th style="white-space: nowrap; padding: 0.2em 0.4em;">満足度</th>
</tr>
</thead>
<tbody>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">count</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">8</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">8</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">8</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">8</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">8</td>
</tr>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">mean</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">2026-01-17 21:00:00</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">39787.5</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">3.5</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">55525</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">4.3125</td>
</tr>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">min</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">2026-01-05 00:00:00</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">2500</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">1</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">11200</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">3.8</td>
</tr>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">10%</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">2026-01-07 02:24:00</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">2710</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">1</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">13860</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">3.94</td>
</tr>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">50%</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">2026-01-17 12:00:00</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">20000</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">2.5</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">44500</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">4.3</td>
</tr>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">90%</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">2026-01-28 21:36:00</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">116500</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">6.5</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">116500</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">4.73</td>
</tr>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">max</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">2026-01-31 00:00:00</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">120000</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">10</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">120000</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">4.8</td>
</tr>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">std</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">NaN</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">49708.8</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">2.9761</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">43928.9</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">0.34821</td>
</tr>
</tbody>
</table>
</div>

<p><code>percentiles=[0.1, 0.5, 0.9]</code> とすると、10%、50%、90%の位置が表示されます。</p>
<p>外れ値の影響や、上位・下位の分布をもう少し細かく見たいときに使えます。</p>
<p>ただし、初心者のうちは、まず標準の <code>25%</code>、<code>50%</code>、<code>75%</code> を読めるようになれば十分です。</p>


<h2><span id="toc16">Series.describe()とDataFrame.describe()の違い</span></h2>
<p><code>describe()</code> は、DataFrame全体にも、1つの列であるSeriesにも使えます。</p>
<p>DataFrameに使う場合は、列ごとに統計量が表示されます。</p>


<pre class="line-numbers"><code class="language-python">df.describe()</code></pre>

<div class="pdl-table-scroll" style="overflow-x: auto; max-width: 100%;">
<table class="wp-block-table" style="width: auto; border-collapse: collapse;">
<thead>
<tr>
<th style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;"></th>
<th style="white-space: nowrap; padding: 0.2em 0.4em;">日付</th>
<th style="white-space: nowrap; padding: 0.2em 0.4em;">単価</th>
<th style="white-space: nowrap; padding: 0.2em 0.4em;">数量</th>
<th style="white-space: nowrap; padding: 0.2em 0.4em;">売上</th>
<th style="white-space: nowrap; padding: 0.2em 0.4em;">満足度</th>
</tr>
</thead>
<tbody>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">count</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">8</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">8</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">8</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">8</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">8</td>
</tr>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">mean</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">2026-01-17 21:00:00</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">39787.5</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">3.5</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">55525</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">4.3125</td>
</tr>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">min</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">2026-01-05 00:00:00</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">2500</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">1</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">11200</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">3.8</td>
</tr>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">25%</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">2026-01-11 00:00:00</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">2950</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">1.75</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">21750</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">4.075</td>
</tr>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">50%</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">2026-01-17 12:00:00</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">20000</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">2.5</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">44500</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">4.3</td>
</tr>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">75%</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">2026-01-25 00:00:00</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">55000</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">4.25</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">81250</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">4.55</td>
</tr>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">max</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">2026-01-31 00:00:00</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">120000</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">10</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">120000</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">4.8</td>
</tr>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">std</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">NaN</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">49708.8</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">2.9761</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">43928.9</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">0.34821</td>
</tr>
</tbody>
</table>
</div>

<p>1つの列だけに使う場合は、Seriesに対して <code>describe()</code> を実行します。</p>


<pre class="line-numbers"><code class="language-python">df["売上"].describe()</code></pre>

<div class="pdl-table-scroll" style="overflow-x: auto; max-width: 100%;">
<table class="wp-block-table" style="width: auto; border-collapse: collapse;">
<thead>
<tr>
<th style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;"></th>
<th style="white-space: nowrap; padding: 0.2em 0.4em;">売上</th>
</tr>
</thead>
<tbody>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">count</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">8</td>
</tr>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">mean</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">55525</td>
</tr>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">std</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">43928.9</td>
</tr>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">min</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">11200</td>
</tr>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">25%</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">21750</td>
</tr>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">50%</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">44500</td>
</tr>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">75%</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">81250</td>
</tr>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">max</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">120000</td>
</tr>
</tbody>
</table>
</div>

<p><code>df["売上"].describe()</code> のように書くと、売上列だけの統計量を確認できます。</p>
<p>特定の列だけ詳しく見たい場合は、Seriesの <code>describe()</code> が便利です。</p>
<p>また、複数列だけ確認したい場合は、次のように列名をリストで指定します。</p>


<pre class="line-numbers"><code class="language-python">df[["単価", "売上"]].describe()</code></pre>

<div class="pdl-table-scroll" style="overflow-x: auto; max-width: 100%;">
<table class="wp-block-table" style="width: auto; border-collapse: collapse;">
<thead>
<tr>
<th style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;"></th>
<th style="white-space: nowrap; padding: 0.2em 0.4em;">単価</th>
<th style="white-space: nowrap; padding: 0.2em 0.4em;">売上</th>
</tr>
</thead>
<tbody>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">count</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">8</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">8</td>
</tr>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">mean</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">39787.5</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">55525</td>
</tr>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">std</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">49708.8</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">43928.9</td>
</tr>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">min</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">2500</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">11200</td>
</tr>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">25%</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">2950</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">21750</td>
</tr>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">50%</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">20000</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">44500</td>
</tr>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">75%</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">55000</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">81250</td>
</tr>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">max</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">120000</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">120000</td>
</tr>
</tbody>
</table>
</div>

<p>ここで、<code>df["売上"]</code> と <code>df[["売上"]]</code> の違いにも注意しましょう。</p>
<div class="pdl-table-scroll" style="overflow-x: auto; max-width: 100%;"><table class="wp-block-table" style="width: auto; border-collapse: collapse;">
<thead>
<tr>
<th style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">書き方</th>
<th style="white-space: nowrap; padding: 0.2em 0.4em;">返るもの</th>
</tr>
</thead>
<tbody>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;"><code>df["売上"]</code></td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">Series</td>
</tr>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;"><code>df[["売上"]]</code></td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">DataFrame</td>
</tr>
</tbody>
</table></div>
<p>初心者のうちは、1列だけなら <code>df["売上"].describe()</code>、複数列なら <code>df[["単価", "売上"]].describe()</code> と覚えるとよいです。</p>


<h2><span id="toc17">describe()とinfo()の違い</span></h2>
<p><code>describe()</code> と一緒に使われることが多いのが <code>info()</code> です。</p>
<p>どちらもDataFrameの確認に使いますが、確認できる内容が違います。</p>
<div class="pdl-table-scroll" style="overflow-x: auto; max-width: 100%;"><table class="wp-block-table" style="width: auto; border-collapse: collapse;">
<thead>
<tr>
<th style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">メソッド</th>
<th style="white-space: nowrap; padding: 0.2em 0.4em;">確認できること</th>
<th style="white-space: nowrap; padding: 0.2em 0.4em;">主な使いどころ</th>
</tr>
</thead>
<tbody>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;"><code>info()</code></td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">行数、列名、欠損値の有無、データ型、メモリ使用量</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">データ構造を確認したいとき</td>
</tr>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;"><code>describe()</code></td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">平均、標準偏差、最小値、中央値、最大値など</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">数値の分布や統計量を確認したいとき</td>
</tr>
</tbody>
</table></div>
<p>実際に <code>info()</code> を実行してみます。</p>


<pre class="line-numbers"><code class="language-python">df.info()</code></pre>

<pre class="colab-output"><code>&lt;class 'pandas.core.frame.DataFrame'&gt;
RangeIndex: 8 entries, 0 to 7
Data columns (total 8 columns):
 #   Column  Non-Null Count  Dtype         
---  ------  --------------  -----         
 0   日付      8 non-null      datetime64[ns]
 1   商品      8 non-null      object        
 2   カテゴリ    8 non-null      object        
 3   店舗      8 non-null      object        
 4   単価      8 non-null      int64         
 5   数量      8 non-null      int64         
 6   売上      8 non-null      int64         
 7   満足度     8 non-null      float64       
dtypes: datetime64[ns](1), float64(1), int64(3), object(3)
memory usage: 644.0+ bytes</code></pre>

<p><code>info()</code> では、列ごとのデータ型や欠損していない件数を確認できます。</p>
<p>一方、<code>describe()</code> では、平均値や標準偏差などの統計量を確認できます。</p>
<p>おすすめの順番は次のとおりです。</p>
<ol>
<li><code>df.info()</code> で列名・型・欠損値を確認する</li>
<li><code>df.describe()</code> で数値列の統計量を確認する</li>
<li><code>df.describe(include='all')</code> で文字列列も含めて確認する</li>
</ol>
<p>この流れにすると、データの全体像をつかみやすくなります。</p>


<h2><span id="toc18">describe()とmean()・std()・quantile()の違い</span></h2>
<p><code>describe()</code> の出力項目は、個別のメソッドでも確認できます。</p>
<div class="pdl-table-scroll" style="overflow-x: auto; max-width: 100%;"><table class="wp-block-table" style="width: auto; border-collapse: collapse;">
<thead>
<tr>
<th style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">確認したいこと</th>
<th style="white-space: nowrap; padding: 0.2em 0.4em;">個別メソッド</th>
</tr>
</thead>
<tbody>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">平均値</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;"><code>mean()</code></td>
</tr>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">標準偏差</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;"><code>std()</code></td>
</tr>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">最小値</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;"><code>min()</code></td>
</tr>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">中央値</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;"><code>median()</code></td>
</tr>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">最大値</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;"><code>max()</code></td>
</tr>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">分位点</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;"><code>quantile()</code></td>
</tr>
</tbody>
</table></div>
<p>たとえば、売上の平均値だけを確認したい場合は、<code>mean()</code> を使えます。</p>


<pre class="line-numbers"><code class="language-python">df["売上"].mean()</code></pre>

<pre class="colab-output"><code>55525.0</code></pre>

<p>売上の標準偏差だけを確認したい場合は、<code>std()</code> を使えます。</p>


<pre class="line-numbers"><code class="language-python">df["売上"].std()</code></pre>

<pre class="colab-output"><code>43928.89546918812</code></pre>

<p>中央値や四分位数を確認したい場合は、<code>quantile()</code> が使えます。</p>


<pre class="line-numbers"><code class="language-python">df["売上"].quantile([0.25, 0.5, 0.75])</code></pre>

<div class="pdl-table-scroll" style="overflow-x: auto; max-width: 100%;">
<table class="wp-block-table" style="width: auto; border-collapse: collapse;">
<thead>
<tr>
<th style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;"></th>
<th style="white-space: nowrap; padding: 0.2em 0.4em;">売上</th>
</tr>
</thead>
<tbody>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">0.25</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">21750</td>
</tr>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">0.5</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">44500</td>
</tr>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">0.75</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">81250</td>
</tr>
</tbody>
</table>
</div>

<p><code>describe()</code> は、これらの統計量をまとめて確認するためのメソッドです。</p>
<div class="pdl-table-scroll" style="overflow-x: auto; max-width: 100%;"><table class="wp-block-table" style="width: auto; border-collapse: collapse;">
<thead>
<tr>
<th style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">場面</th>
<th style="white-space: nowrap; padding: 0.2em 0.4em;">おすすめ</th>
</tr>
</thead>
<tbody>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">まず全体像を見たい</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;"><code>describe()</code></td>
</tr>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">平均だけ知りたい</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;"><code>mean()</code></td>
</tr>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">ばらつきだけ見たい</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;"><code>std()</code></td>
</tr>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">中央値や四分位数を詳しく見たい</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;"><code>quantile()</code></td>
</tr>
</tbody>
</table></div>
<p>最初は <code>describe()</code> で全体を確認し、気になる列があれば個別メソッドで深掘りするとよいです。</p>


<h2><span id="toc19">describe()で外れ値や極端な値に気づく例</span></h2>
<p><code>describe()</code> は、外れ値や極端な値に気づく入口としても役立ちます。</p>
<p>ここでは、売上に極端に大きい値が1つ入ったデータを作って、<code>describe()</code> の見え方を確認します。</p>


<pre class="line-numbers"><code class="language-python">df_outlier = df.copy()
df_outlier.loc[7, "売上"] = 700000

df_outlier[["商品", "売上"]]</code></pre>

<div class="pdl-table-scroll" style="overflow-x: auto; max-width: 100%;">
<table class="wp-block-table" style="width: auto; border-collapse: collapse;">
<thead>
<tr>
<th style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;"></th>
<th style="white-space: nowrap; padding: 0.2em 0.4em;">商品</th>
<th style="white-space: nowrap; padding: 0.2em 0.4em;">売上</th>
</tr>
</thead>
<tbody>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">0</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">ノートPC</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">120000</td>
</tr>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">1</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">マウス</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">15000</td>
</tr>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">2</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">キーボード</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">24000</td>
</tr>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">3</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">モニター</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">64000</td>
</tr>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">4</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">USBメモリ</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">25000</td>
</tr>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">5</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">ノートPC</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">115000</td>
</tr>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">6</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">マウス</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">11200</td>
</tr>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">7</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">モニター</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">700000</td>
</tr>
</tbody>
</table>
</div>

<pre class="line-numbers"><code class="language-python">df_outlier["売上"].describe()</code></pre>

<div class="pdl-table-scroll" style="overflow-x: auto; max-width: 100%;">
<table class="wp-block-table" style="width: auto; border-collapse: collapse;">
<thead>
<tr>
<th style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;"></th>
<th style="white-space: nowrap; padding: 0.2em 0.4em;">売上</th>
</tr>
</thead>
<tbody>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">count</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">8</td>
</tr>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">mean</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">134275</td>
</tr>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">std</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">232697</td>
</tr>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">min</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">11200</td>
</tr>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">25%</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">21750</td>
</tr>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">50%</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">44500</td>
</tr>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">75%</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">116250</td>
</tr>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">max</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">700000</td>
</tr>
</tbody>
</table>
</div>

<p>この例では、<code>max</code> が大きくなり、<code>mean</code> も引き上げられます。</p>
<p>一方で、<code>50%</code> の中央値は、極端な値の影響を平均値ほど大きく受けません。</p>
<p>このように、<code>describe()</code> を見るときは、次の組み合わせで確認すると実務で使いやすくなります。</p>
<div class="pdl-table-scroll" style="overflow-x: auto; max-width: 100%;"><table class="wp-block-table" style="width: auto; border-collapse: collapse;">
<thead>
<tr>
<th style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">見る項目</th>
<th style="white-space: nowrap; padding: 0.2em 0.4em;">チェックすること</th>
</tr>
</thead>
<tbody>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;"><code>mean</code> と <code>50%</code></td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">平均値と中央値が大きく離れていないか</td>
</tr>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;"><code>min</code> と <code>max</code></td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">極端に小さい値・大きい値がないか</td>
</tr>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;"><code>std</code></td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">ばらつきが大きすぎないか</td>
</tr>
</tbody>
</table></div>
<p><code>describe()</code> だけで外れ値を完全に判断することはできませんが、外れ値に気づく最初のチェックとして有効です。</p>


<h2><span id="toc20">欠損値がある場合のdescribe()の見方</span></h2>
<p><code>describe()</code> の <code>count</code> は、欠損値を除いた件数です。</p>
<p>ここでは、あえて欠損値を含むDataFrameを作って確認します。</p>


<pre class="line-numbers"><code class="language-python">df_nan = df.copy()
df_nan.loc[2, "売上"] = pd.NA
df_nan.loc[5, "満足度"] = pd.NA

df_nan</code></pre>

<div class="pdl-table-scroll" style="overflow-x: auto; max-width: 100%;">
<table class="wp-block-table" style="width: auto; border-collapse: collapse;">
<thead>
<tr>
<th style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;"></th>
<th style="white-space: nowrap; padding: 0.2em 0.4em;">日付</th>
<th style="white-space: nowrap; padding: 0.2em 0.4em;">商品</th>
<th style="white-space: nowrap; padding: 0.2em 0.4em;">カテゴリ</th>
<th style="white-space: nowrap; padding: 0.2em 0.4em;">店舗</th>
<th style="white-space: nowrap; padding: 0.2em 0.4em;">単価</th>
<th style="white-space: nowrap; padding: 0.2em 0.4em;">数量</th>
<th style="white-space: nowrap; padding: 0.2em 0.4em;">売上</th>
<th style="white-space: nowrap; padding: 0.2em 0.4em;">満足度</th>
</tr>
</thead>
<tbody>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">0</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">2026-01-05 00:00:00</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">ノートPC</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">PC</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">東京</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">120000</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">1</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">120000</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">4.8</td>
</tr>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">1</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">2026-01-08 00:00:00</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">マウス</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">周辺機器</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">東京</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">3000</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">5</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">15000</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">4.2</td>
</tr>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">2</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">2026-01-12 00:00:00</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">キーボード</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">周辺機器</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">大阪</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">8000</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">3</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">NaN</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">4</td>
</tr>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">3</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">2026-01-15 00:00:00</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">モニター</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">周辺機器</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">大阪</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">32000</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">2</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">64000</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">4.5</td>
</tr>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">4</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">2026-01-20 00:00:00</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">USBメモリ</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">記録媒体</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">名古屋</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">2500</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">10</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">25000</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">3.8</td>
</tr>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">5</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">2026-01-24 00:00:00</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">ノートPC</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">PC</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">東京</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">115000</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">1</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">115000</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">NaN</td>
</tr>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">6</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">2026-01-28 00:00:00</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">マウス</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">周辺機器</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">名古屋</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">2800</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">4</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">11200</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">4.1</td>
</tr>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">7</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">2026-01-31 00:00:00</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">モニター</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">周辺機器</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">大阪</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">35000</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">2</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">70000</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">4.4</td>
</tr>
</tbody>
</table>
</div>

<pre class="line-numbers"><code class="language-python">df_nan.describe()</code></pre>

<div class="pdl-table-scroll" style="overflow-x: auto; max-width: 100%;">
<table class="wp-block-table" style="width: auto; border-collapse: collapse;">
<thead>
<tr>
<th style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;"></th>
<th style="white-space: nowrap; padding: 0.2em 0.4em;">日付</th>
<th style="white-space: nowrap; padding: 0.2em 0.4em;">単価</th>
<th style="white-space: nowrap; padding: 0.2em 0.4em;">数量</th>
<th style="white-space: nowrap; padding: 0.2em 0.4em;">売上</th>
<th style="white-space: nowrap; padding: 0.2em 0.4em;">満足度</th>
</tr>
</thead>
<tbody>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">count</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">8</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">8</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">8</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">7</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">7</td>
</tr>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">mean</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">2026-01-17 21:00:00</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">39787.5</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">3.5</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">60028.6</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">4.25714</td>
</tr>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">min</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">2026-01-05 00:00:00</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">2500</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">1</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">11200</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">3.8</td>
</tr>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">25%</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">2026-01-11 00:00:00</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">2950</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">1.75</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">20000</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">4.05</td>
</tr>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">50%</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">2026-01-17 12:00:00</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">20000</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">2.5</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">64000</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">4.2</td>
</tr>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">75%</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">2026-01-25 00:00:00</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">55000</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">4.25</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">92500</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">4.45</td>
</tr>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">max</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">2026-01-31 00:00:00</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">120000</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">10</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">120000</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">4.8</td>
</tr>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">std</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">NaN</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">49708.8</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">2.9761</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">45410</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">0.335942</td>
</tr>
</tbody>
</table>
</div>

<p>元のデータは8行ですが、欠損値が入った列では <code>count</code> が8より小さくなります。</p>
<p>このように、<code>describe()</code> の <code>count</code> を見ると、欠損値の有無に気づくきっかけになります。</p>
<p>ただし、欠損値を正確に確認するなら、<code>isnull().sum()</code> を使う方がわかりやすいです。</p>


<pre class="line-numbers"><code class="language-python">df_nan.isnull().sum()</code></pre>

<div class="pdl-table-scroll" style="overflow-x: auto; max-width: 100%;">
<table class="wp-block-table" style="width: auto; border-collapse: collapse;">
<thead>
<tr>
<th style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;"></th>
<th style="white-space: nowrap; padding: 0.2em 0.4em;"></th>
</tr>
</thead>
<tbody>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">日付</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">0</td>
</tr>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">商品</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">0</td>
</tr>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">カテゴリ</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">0</td>
</tr>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">店舗</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">0</td>
</tr>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">単価</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">0</td>
</tr>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">数量</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">0</td>
</tr>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">売上</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">1</td>
</tr>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">満足度</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">1</td>
</tr>
</tbody>
</table>
</div>

<p><code>describe()</code> は欠損値チェックの入口にはなりますが、欠損値の場所や件数を詳しく見るには <code>isnull()</code> と組み合わせるのがおすすめです。</p>


<h2><span id="toc21">よくあるミス</span></h2>
<p>ここでは、<code>describe()</code> を使うときに初心者がつまずきやすいポイントを整理します。</p>
<h3><span id="toc22">数値列しか表示されないと思って混乱する</span></h3>
<p><code>df.describe()</code> は、標準では主に数値列を対象にします。</p>
<p>文字列列も確認したい場合は、<code>include='all'</code> や <code>include='object'</code> を使います。</p>
<pre class="line-numbers"><code class="language-python">df.describe(include='all')
df.describe(include='object')
</code></pre>
<h3><span id="toc23">countを行数だと思ってしまう</span></h3>
<p><code>count</code> は、欠損値を除いた件数です。</p>
<p>行数そのものを確認したい場合は、<code>len(df)</code> や <code>df.shape</code> を使います。</p>
<h3><span id="toc24">50%を平均値だと思ってしまう</span></h3>
<p><code>50%</code> は中央値です。</p>
<p>平均値は <code>mean</code> です。</p>
<p>平均値と中央値は違うので、混同しないようにしましょう。</p>
<h3><span id="toc25">stdの意味がわからないまま読み飛ばす</span></h3>
<p><code>std</code> は標準偏差で、値のばらつきを表します。</p>
<p>細かい数式まで理解しなくても、初心者のうちは「大きいほどばらつきが大きい」と考えれば十分です。</p>
<h3><span id="toc26">include=&#8217;all&#8217;でNaNが出て不安になる</span></h3>
<p><code>include='all'</code> では、数値列にしか意味がない項目、文字列列にしか意味がない項目が混在します。</p>
<p>そのため、該当しない部分に <code>NaN</code> が出ることがあります。</p>
<p>これはエラーではありません。</p>


<h2><span id="toc27">実務でのおすすめ確認手順</span></h2>
<p>CSVやExcelを読み込んだあと、最初に何を確認すればよいかわからない場合は、次の順番がおすすめです。</p>
<pre class="line-numbers"><code class="language-python">df.head()
df.info()
df.describe()
df.describe(include='all')
df.isnull().sum()
</code></pre>
<p>それぞれの役割は次のとおりです。</p>
<div class="pdl-table-scroll" style="overflow-x: auto; max-width: 100%;"><table class="wp-block-table" style="width: auto; border-collapse: collapse;">
<thead>
<tr>
<th style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">手順</th>
<th style="white-space: nowrap; padding: 0.2em 0.4em;">使うメソッド</th>
<th style="white-space: nowrap; padding: 0.2em 0.4em;">確認すること</th>
</tr>
</thead>
<tbody>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">1</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;"><code>head()</code></td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">データの先頭を確認</td>
</tr>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">2</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;"><code>info()</code></td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">列名・型・欠損値を確認</td>
</tr>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">3</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;"><code>describe()</code></td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">数値列の統計量を確認</td>
</tr>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">4</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;"><code>describe(include='all')</code></td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">文字列列も含めて確認</td>
</tr>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">5</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;"><code>isnull().sum()</code></td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">欠損値の件数を確認</td>
</tr>
</tbody>
</table></div>
<p>この流れを覚えておくと、データ分析の最初の確認で迷いにくくなります。</p>


<h2><span id="toc28">まとめ</span></h2>
<p>この記事では、<code>pandas</code> の <code>describe()</code> の使い方を解説しました。</p>
<p><code>describe()</code> は、DataFrameやSeriesの要約統計量をまとめて確認するメソッドです。</p>
<p>特に数値列では、次の項目を確認できます。</p>
<div class="pdl-table-scroll" style="overflow-x: auto; max-width: 100%;"><table class="wp-block-table" style="width: auto; border-collapse: collapse;">
<thead>
<tr>
<th style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">項目</th>
<th style="white-space: nowrap; padding: 0.2em 0.4em;">意味</th>
</tr>
</thead>
<tbody>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;"><code>count</code></td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">欠損値を除いた件数</td>
</tr>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;"><code>mean</code></td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">平均値</td>
</tr>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;"><code>std</code></td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">標準偏差</td>
</tr>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;"><code>min</code></td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">最小値</td>
</tr>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;"><code>25%</code></td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">第1四分位数</td>
</tr>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;"><code>50%</code></td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">中央値</td>
</tr>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;"><code>75%</code></td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">第3四分位数</td>
</tr>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;"><code>max</code></td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">最大値</td>
</tr>
</tbody>
</table></div>
<p>重要なポイントは次のとおりです。</p>
<ul>
<li><code>df.describe()</code> は標準では数値列を中心に表示する</li>
<li>文字列列も含めたい場合は <code>include='all'</code> を使う</li>
<li>文字列列だけ確認したい場合は <code>include='object'</code> を使う</li>
<li>数値列を除外したい場合は <code>exclude='number'</code> を使う</li>
<li><code>percentiles</code> で表示する分位点を変更できる</li>
<li>日付列では、件数や最小日付・最大日付の確認に使える</li>
<li><code>mean</code> と <code>50%</code>、<code>min</code> と <code>max</code> を見ると、外れ値や偏りに気づきやすい</li>
<li><code>describe()</code> は統計量、<code>info()</code> は型・欠損値・列構造の確認に向いている</li>
<li>まず <code>info()</code> で構造を確認し、その後 <code>describe()</code> で数値の特徴を見るとよい</li>
</ul>
<p><code>describe()</code> を使いこなせるようになると、データを読み込んだ直後に、平均値・ばらつき・外れ値・欠損値の手がかりをすばやく確認できます。</p>


<h2><span id="toc29">公式ドキュメント</span></h2>
<p>より詳しい仕様を確認したい場合は、pandas公式ドキュメントも参考になります。</p>
<ul>
<li><a rel="noopener" href="https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.describe.html" target="_blank">pandas.DataFrame.describe 公式ドキュメント</a></li>
<li><a rel="noopener" href="https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.Series.describe.html" target="_blank">pandas.Series.describe 公式ドキュメント</a></li>
</ul>
<p>初心者のうちは、この記事で基本的な読み方を押さえたうえで、引数や細かい仕様を公式ドキュメントで確認する流れがおすすめです。</p>


<h2><span id="toc30">次に読みたい関連記事</span></h2>
<p><code>describe()</code> を理解したあとは、次の記事もあわせて読むと、DataFrameの確認・前処理・集計までつながりやすくなります。</p>
<ul>
<li><a href="https://pythondatalab.com/pandas-dataframe/" target="_blank">Pandas DataFrame入門｜作り方・基本操作をわかりやすく解説</a></li>
<li><a href="https://pythondatalab.com/pandas-head/" target="_blank">Pandas head()の使い方｜先頭の表示・行数指定（df.head(n)）を例で解説</a></li>
<li><a href="https://pythondatalab.com/pandas-isnull/" target="_blank">欠損値を可視化して攻略！Pandas isnullとヒートマップ活用術</a></li>
<li><a href="https://pythondatalab.com/pandas-fillna/" target="_blank">pandas fillna()の使い方｜欠損値を0・平均値・中央値・最頻値で埋める方法を初心者向けに解説</a></li>
<li><a href="https://pythondatalab.com/pandas-to-numeric/" target="_blank">pandas to_numeric()の使い方｜文字列の数字を数値に変換する方法</a></li>
<li><a href="https://pythondatalab.com/pandas-astype/" target="_blank">pandas astype()の使い方｜文字列・数値への型変換とエラー対処を初心者向けに解説</a></li>
<li><a href="https://pythondatalab.com/pandas-select-dtypes/" target="_blank">pandas select_dtypes()の使い方｜データ型で列を選ぶ方法を初心者向けに解説</a></li>
<li><a href="https://pythondatalab.com/pandas-value-counts/" target="_blank">pandas value_counts()の使い方｜件数集計・割合表示・欠損値の数え方を解説</a></li>
<li><a href="https://pythondatalab.com/google-colab-csv/" target="_blank">Google ColabでCSVを読み込む方法｜Drive連携とpandas read_csvを初心者向けに解説</a></li>
</ul>

<!-- ▼▼▼ カテゴリから探す　 共通スタイル（カテゴリ）▼▼▼ -->
<style> .related-box { border: 2px solid #0073aa; border-radius: 10px; padding: 1em 1.2em; margin-top: 2em; background: #f8faff; } .related-box h3 { margin-top: 0; color: #0073aa; } .related-box ul { list-style-type: none; margin: 0; padding: 0; } .related-box li { margin: 0.4em 0; } .related-box a { text-decoration: none; color: #333; } .related-box a:hover { text-decoration: underline; color: #0073aa; } </style> <div class="related-box"> <h3><span id="toc31"> カテゴリから探す</span></h3> <ul>
<ul>
<li><a href="https://pythondatalab.com/category/pandas/basic/">◀ Pandas 基礎</a></li>
<li><a href="https://pythondatalab.com/category/pandas/preprocessing/">◀ Pandas 抽出・前処理</a></li>
<li><a href="https://pythondatalab.com/category/pandas/aggregation/">◀ Pandas 集計・変形</a></li>
<li><a href="https://pythondatalab.com/category/pandas/visualization/">▶ Matplotlib　可視化</a></li> </ul> </ul></div>
<!-- ▼▼▼ カテゴリから探す　共通スタイル（カテゴリ）終了▼▼▼ -->
<p style="text-align: center; margin-top: 2em;"><a href="#top">▲ ページトップへ戻る</a></p>



</div>
<p>&lt;p&gt;The post <a rel="nofollow" href="https://pythondatalab.com/pandas-info-describe/">pandas describe()の使い方｜統計量の意味・include=&#8217;all&#8217;・info()との違いを解説</a> first appeared on <a rel="nofollow" href="https://pythondatalab.com">Python Data Lab（Pythonデータラボ）</a>.&lt;/p&gt;</p>
]]></content:encoded>
					
					<wfw:commentRss>https://pythondatalab.com/pandas-info-describe/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>pandas head()の使い方｜df.head()で先頭5行を表示・tail()との違いも解説</title>
		<link>https://pythondatalab.com/pandas-head/</link>
					<comments>https://pythondatalab.com/pandas-head/#respond</comments>
		
		<dc:creator><![CDATA[coin_collector]]></dc:creator>
		<pubDate>Sat, 12 Apr 2025 11:41:00 +0000</pubDate>
				<category><![CDATA[基礎]]></category>
		<guid isPermaLink="false"></guid>

					<description><![CDATA[<p>pandasのhead()でDataFrameの先頭行を表示する方法を初心者向けに解説。df.head()で最初の5行が表示される仕組み、head(10)などの行数指定、tail()・sample()との違い、CSV読み込み後の確認方法まで出力例つきで紹介します。</p>
<p>&lt;p&gt;The post <a rel="nofollow" href="https://pythondatalab.com/pandas-head/">pandas head()の使い方｜df.head()で先頭5行を表示・tail()との違いも解説</a> first appeared on <a rel="nofollow" href="https://pythondatalab.com">Python Data Lab（Pythonデータラボ）</a>.&lt;/p&gt;</p>
]]></description>
										<content:encoded><![CDATA[
<div class="colab-article">

<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/prismjs/themes/prism-tomorrow.min.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/prismjs/plugins/toolbar/prism-toolbar.min.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/prismjs/plugins/line-numbers/prism-line-numbers.min.css">

<script src="https://cdn.jsdelivr.net/npm/prismjs/components/prism-core.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/prismjs/components/prism-clike.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/prismjs/components/prism-python.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/prismjs/plugins/line-numbers/prism-line-numbers.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/prismjs/plugins/toolbar/prism-toolbar.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/prismjs/plugins/copy-to-clipboard/prism-copy-to-clipboard.min.js"></script>

<style>
  .colab-article {
    max-width: 100%;
  }
  .colab-article pre[class*="language-"] {
    margin: 0 !important;
    padding: 1em;
    overflow-x: auto;
  }
  .colab-article pre.colab-output {
    margin: 0 !important;
    padding: 0.8em 1em;
    background: #f5f5f5;
    overflow-x: auto;
    border-radius: 4px;
  }
  .colab-article pre.colab-output code {
    background: transparent;
    padding: 0;
    white-space: pre;
  }
  .colab-article code {
    font-family: Consolas, Monaco, 'Courier New', monospace;
  }
  .colab-article :not(pre) > code {
    background: #f5f5f5;
    padding: 0.1em 0.3em;
    border-radius: 3px;
  }
  .colab-article .pdl-table-scroll {
    overflow-x: auto;
    max-width: 100%;
    margin: 0.8em 0;
  }
  .colab-article table.wp-block-table {
    width: auto;
    border-collapse: collapse;
  }
  .colab-article table.wp-block-table th,
  .colab-article table.wp-block-table td {
    border: 1px solid #ddd;
  }
  .colab-article figure.colab-figure {
    margin: 1em 0;
  }
  .colab-article figure.colab-figure img {
    max-width: 100%;
    height: auto;
  }
</style>

<script>Prism.highlightAll();</script>

<p><code>pandas</code> の <code>head()</code> は、DataFrameやSeriesの<strong>先頭行を表示するメソッド</strong>です。</p>
<p>何も指定せずに <code>df.head()</code> と書くと、標準では<strong>先頭5行</strong>が表示されます。</p>
<p>CSVやExcelを読み込んだあと、まず <code>df.head()</code> で先頭を確認すると、列名・値の入り方・データの読み込み状態をすばやくチェックできます。</p>
<p>この記事では、<code>df.head()</code> の基本、<code>head(10)</code> のような行数指定、<code>tail()</code> との違い、<code>sample()</code> との使い分け、CSV読み込み後の確認方法まで、初心者向けに出力例つきで解説します。</p>


<p><strong>この記事でわかること</strong></p>
<ul>
<li><code>df.head()</code> の意味</li>
<li><code>df.head()</code> で先頭5行が表示される仕組み</li>
<li><code>df.head(10)</code> のように表示行数を指定する方法</li>
<li><code>head()</code>、<code>tail()</code>、<code>sample()</code> の違い</li>
<li>CSVを読み込んだあとに <code>head()</code> で確認する流れ</li>
<li><code>print(df.head())</code>、<code>head(0)</code>、<code>df.columns</code> の使い分け</li>
<li>DataFrameだけでなくSeriesでも <code>head()</code> が使えること</li>
<li>先頭1行を表示する <code>df.head(1)</code> と、値を取り出す <code>df.iloc[0]</code> の違い</li>
</ul>



  <div id="toc" class="toc tnt-number toc-center tnt-number border-element"><input type="checkbox" class="toc-checkbox" id="toc-checkbox-3" checked><label class="toc-title" for="toc-checkbox-3">目次</label>
    <div class="toc-content">
    <ol class="toc-list open"><li><a href="#toc1" tabindex="0">pandas head()とは？DataFrameの先頭行を表示するメソッド</a></li><li><a href="#toc2" tabindex="0">サンプルデータを用意する</a></li><li><a href="#toc3" tabindex="0">df.head()の基本的な使い方</a><ol><li><a href="#toc4" tabindex="0">df.head()は何も指定しないと先頭5行を表示する</a></li><li><a href="#toc5" tabindex="0">df.head(10)で表示する行数を指定する</a></li></ol></li><li><a href="#toc6" tabindex="0">head()とtail()・sample()の違い</a><ol><li><a href="#toc7" tabindex="0">head()とtail()の違い</a></li><li><a href="#toc8" tabindex="0">head()・tail()・sample()の使い分け</a></li></ol></li><li><a href="#toc9" tabindex="0">CSVを読み込んだあとにhead()で確認する流れ</a></li><li><a href="#toc10" tabindex="0">head()の補足的な使い方</a><ol><li><a href="#toc11" tabindex="0">df.head()とprint(df.head())の違い</a></li><li><a href="#toc12" tabindex="0">head(0)でカラム名だけ確認する</a></li><li><a href="#toc13" tabindex="0">Seriesでもhead()は使える</a></li><li><a href="#toc14" tabindex="0">スライスで先頭行を確認する方法との違い</a></li><li><a href="#toc15" tabindex="0">先頭1行だけ確認する・値を取り出す場合</a></li></ol></li><li><a href="#toc16" tabindex="0">よくあるミス</a><ol><li><a href="#toc17" tabindex="0">df.head()を書いても全データが表示されると思ってしまう</a></li><li><a href="#toc18" tabindex="0">df.head(10)で必ず10行表示されると思ってしまう</a></li><li><a href="#toc19" tabindex="0">tail()との違いを混同する</a></li><li><a href="#toc20" tabindex="0">print(df.head())を毎回使う必要があると思ってしまう</a></li><li><a href="#toc21" tabindex="0">head()だけ見てデータ全体を判断してしまう</a></li><li><a href="#toc22" tabindex="0">head()で値を取り出そうとしてしまう</a></li></ol></li><li><a href="#toc23" tabindex="0">実務でのおすすめ確認手順</a></li><li><a href="#toc24" tabindex="0">まとめ</a></li><li><a href="#toc25" tabindex="0">次に読みたい関連記事</a></li><li><a href="#toc26" tabindex="0">公式ドキュメント</a><ol><li><a href="#toc27" tabindex="0"> カテゴリから探す</a></li><li><a href="#toc28" tabindex="0">pandasのhead()は何をするメソッドですか？</a></li><li><a href="#toc29" tabindex="0">df.head()は何行表示しますか？</a></li><li><a href="#toc30" tabindex="0">df.head(10)とは何ですか？</a></li><li><a href="#toc31" tabindex="0">head()とtail()の違いは何ですか？</a></li><li><a href="#toc32" tabindex="0">head()とsample()はどう使い分けますか？</a></li><li><a href="#toc33" tabindex="0">Seriesにもhead()は使えますか？</a></li><li><a href="#toc34" tabindex="0">Google Colabではprint(df.head())が必要ですか？</a></li><li><a href="#toc35" tabindex="0">head(0)は何に使いますか？</a></li><li><a href="#toc36" tabindex="0">先頭1行だけ表示するにはどうすればよいですか？</a></li></ol></li></ol>
    </div>
  </div>

<h2><span id="toc1">pandas head()とは？DataFrameの先頭行を表示するメソッド</span></h2>
<p><code>head()</code> は、DataFrameやSeriesの先頭部分を確認するためのメソッドです。</p>
<p>基本形は次のとおりです。</p>
<pre class="line-numbers"><code class="language-python">df.head()
</code></pre>
<p><code>df.head()</code> を使うと、DataFrameの最初の数行を表示できます。</p>
<p>大きなデータを扱うとき、全行を表示すると見づらくなるため、まずは <code>head()</code> で先頭だけ確認するのが実務でもよく使われる流れです。</p>
<div class="pdl-table-scroll" style="overflow-x: auto; max-width: 100%;"><table class="wp-block-table" style="width: auto; border-collapse: collapse;">
<thead>
<tr>
<th style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">メソッド</th>
<th style="white-space: nowrap; padding: 0.2em 0.4em;">役割</th>
</tr>
</thead>
<tbody>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;"><code>df.head()</code></td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">先頭5行を表示</td>
</tr>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;"><code>df.head(n)</code></td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">先頭n行を表示</td>
</tr>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;"><code>df.tail()</code></td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">末尾5行を表示</td>
</tr>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;"><code>df.sample()</code></td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">ランダムに行を表示</td>
</tr>
</tbody>
</table></div>


<h2><span id="toc2">サンプルデータを用意する</span></h2>
<p>ここでは、売上データを例にします。</p>
<p><code>商品</code>、<code>カテゴリ</code>、<code>店舗</code>、<code>売上</code>、<code>数量</code> を持つDataFrameを作成します。</p>


<pre class="line-numbers"><code class="language-python">import pandas as pd

df = pd.DataFrame({
    "注文ID": [101, 102, 103, 104, 105, 106, 107, 108],
    "商品": ["ノートPC", "マウス", "キーボード", "モニター", "USBメモリ", "ノートPC", "マウス", "モニター"],
    "カテゴリ": ["PC", "周辺機器", "周辺機器", "周辺機器", "記録媒体", "PC", "周辺機器", "周辺機器"],
    "店舗": ["東京", "東京", "大阪", "大阪", "名古屋", "東京", "名古屋", "大阪"],
    "数量": [1, 5, 3, 2, 10, 1, 4, 2],
    "売上": [120000, 15000, 24000, 64000, 25000, 115000, 11200, 70000]
})

df</code></pre>

<div class="pdl-table-scroll" style="overflow-x: auto; max-width: 100%;">
<table class="wp-block-table" style="width: auto; border-collapse: collapse;">
  <thead>
    <tr>
      <th style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;"></th>
      <th style="white-space: nowrap; padding: 0.2em 0.4em;">注文ID</th>
      <th style="white-space: nowrap; padding: 0.2em 0.4em;">商品</th>
      <th style="white-space: nowrap; padding: 0.2em 0.4em;">カテゴリ</th>
      <th style="white-space: nowrap; padding: 0.2em 0.4em;">店舗</th>
      <th style="white-space: nowrap; padding: 0.2em 0.4em;">数量</th>
      <th style="white-space: nowrap; padding: 0.2em 0.4em;">売上</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">0</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">101</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">ノートPC</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">PC</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">東京</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">1</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">120000</td>
    </tr>
    <tr>
      <td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">1</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">102</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">マウス</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">周辺機器</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">東京</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">5</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">15000</td>
    </tr>
    <tr>
      <td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">2</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">103</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">キーボード</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">周辺機器</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">大阪</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">3</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">24000</td>
    </tr>
    <tr>
      <td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">3</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">104</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">モニター</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">周辺機器</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">大阪</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">2</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">64000</td>
    </tr>
    <tr>
      <td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">4</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">105</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">USBメモリ</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">記録媒体</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">名古屋</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">10</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">25000</td>
    </tr>
    <tr>
      <td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">5</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">106</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">ノートPC</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">PC</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">東京</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">1</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">115000</td>
    </tr>
    <tr>
      <td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">6</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">107</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">マウス</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">周辺機器</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">名古屋</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">4</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">11200</td>
    </tr>
    <tr>
      <td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">7</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">108</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">モニター</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">周辺機器</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">大阪</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">2</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">70000</td>
    </tr>
  </tbody>
</table>
</div>

<p>このDataFrameを使って、<code>head()</code> の使い方を確認していきます。</p>


<h2><span id="toc3">df.head()の基本的な使い方</span></h2>
<p>ここでは、<code>df.head()</code> の標準表示と、表示行数の指定方法を確認します。</p>


<h3><span id="toc4">df.head()は何も指定しないと先頭5行を表示する</span></h3>
<p><code>df.head()</code> を実行すると、DataFrameの先頭5行が表示されます。</p>


<pre class="line-numbers"><code class="language-python">df.head()</code></pre>

<div class="pdl-table-scroll" style="overflow-x: auto; max-width: 100%;">
<table class="wp-block-table" style="width: auto; border-collapse: collapse;">
  <thead>
    <tr>
      <th style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;"></th>
      <th style="white-space: nowrap; padding: 0.2em 0.4em;">注文ID</th>
      <th style="white-space: nowrap; padding: 0.2em 0.4em;">商品</th>
      <th style="white-space: nowrap; padding: 0.2em 0.4em;">カテゴリ</th>
      <th style="white-space: nowrap; padding: 0.2em 0.4em;">店舗</th>
      <th style="white-space: nowrap; padding: 0.2em 0.4em;">数量</th>
      <th style="white-space: nowrap; padding: 0.2em 0.4em;">売上</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">0</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">101</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">ノートPC</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">PC</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">東京</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">1</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">120000</td>
    </tr>
    <tr>
      <td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">1</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">102</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">マウス</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">周辺機器</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">東京</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">5</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">15000</td>
    </tr>
    <tr>
      <td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">2</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">103</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">キーボード</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">周辺機器</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">大阪</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">3</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">24000</td>
    </tr>
    <tr>
      <td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">3</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">104</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">モニター</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">周辺機器</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">大阪</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">2</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">64000</td>
    </tr>
    <tr>
      <td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">4</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">105</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">USBメモリ</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">記録媒体</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">名古屋</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">10</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">25000</td>
    </tr>
  </tbody>
</table>
</div>

<p><code>df.head()</code> の結果を見ると、先頭から5行だけが表示されます。</p>
<p>ここで確認したいのは、主に次のような点です。</p>
<ul>
<li>列名が想定どおりか</li>
<li>文字化けしていないか</li>
<li>数値列が正しく読み込まれているか</li>
<li>不自然な値が入っていないか</li>
<li>データの雰囲気が想定と合っているか</li>
</ul>
<p>特にCSVやExcelを読み込んだ直後は、まず <code>df.head()</code> で先頭を確認すると安心です。</p>


<h3><span id="toc5">df.head(10)で表示する行数を指定する</span></h3>
<p><code>head()</code> の引数に数値を指定すると、表示する行数を変更できます。</p>
<p>たとえば、先頭3行だけ表示したい場合は、次のように書きます。</p>


<pre class="line-numbers"><code class="language-python">df.head(3)</code></pre>

<div class="pdl-table-scroll" style="overflow-x: auto; max-width: 100%;">
<table class="wp-block-table" style="width: auto; border-collapse: collapse;">
  <thead>
    <tr>
      <th style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;"></th>
      <th style="white-space: nowrap; padding: 0.2em 0.4em;">注文ID</th>
      <th style="white-space: nowrap; padding: 0.2em 0.4em;">商品</th>
      <th style="white-space: nowrap; padding: 0.2em 0.4em;">カテゴリ</th>
      <th style="white-space: nowrap; padding: 0.2em 0.4em;">店舗</th>
      <th style="white-space: nowrap; padding: 0.2em 0.4em;">数量</th>
      <th style="white-space: nowrap; padding: 0.2em 0.4em;">売上</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">0</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">101</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">ノートPC</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">PC</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">東京</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">1</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">120000</td>
    </tr>
    <tr>
      <td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">1</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">102</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">マウス</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">周辺機器</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">東京</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">5</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">15000</td>
    </tr>
    <tr>
      <td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">2</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">103</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">キーボード</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">周辺機器</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">大阪</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">3</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">24000</td>
    </tr>
  </tbody>
</table>
</div>

<p>先頭10行を表示したい場合は、<code>df.head(10)</code> と書きます。</p>


<pre class="line-numbers"><code class="language-python">df.head(10)</code></pre>

<div class="pdl-table-scroll" style="overflow-x: auto; max-width: 100%;">
<table class="wp-block-table" style="width: auto; border-collapse: collapse;">
  <thead>
    <tr>
      <th style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;"></th>
      <th style="white-space: nowrap; padding: 0.2em 0.4em;">注文ID</th>
      <th style="white-space: nowrap; padding: 0.2em 0.4em;">商品</th>
      <th style="white-space: nowrap; padding: 0.2em 0.4em;">カテゴリ</th>
      <th style="white-space: nowrap; padding: 0.2em 0.4em;">店舗</th>
      <th style="white-space: nowrap; padding: 0.2em 0.4em;">数量</th>
      <th style="white-space: nowrap; padding: 0.2em 0.4em;">売上</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">0</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">101</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">ノートPC</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">PC</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">東京</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">1</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">120000</td>
    </tr>
    <tr>
      <td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">1</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">102</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">マウス</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">周辺機器</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">東京</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">5</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">15000</td>
    </tr>
    <tr>
      <td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">2</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">103</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">キーボード</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">周辺機器</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">大阪</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">3</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">24000</td>
    </tr>
    <tr>
      <td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">3</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">104</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">モニター</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">周辺機器</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">大阪</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">2</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">64000</td>
    </tr>
    <tr>
      <td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">4</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">105</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">USBメモリ</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">記録媒体</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">名古屋</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">10</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">25000</td>
    </tr>
    <tr>
      <td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">5</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">106</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">ノートPC</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">PC</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">東京</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">1</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">115000</td>
    </tr>
    <tr>
      <td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">6</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">107</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">マウス</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">周辺機器</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">名古屋</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">4</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">11200</td>
    </tr>
    <tr>
      <td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">7</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">108</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">モニター</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">周辺機器</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">大阪</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">2</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">70000</td>
    </tr>
  </tbody>
</table>
</div>

<p>今回のDataFrameは8行しかないため、<code>df.head(10)</code> としても全8行が表示されます。</p>
<p>つまり、指定した行数がDataFrameの行数より多い場合でも、エラーにはならず、存在する行だけが表示されます。</p>
<div class="pdl-table-scroll" style="overflow-x: auto; max-width: 100%;"><table class="wp-block-table" style="width: auto; border-collapse: collapse;">
<thead>
<tr>
<th style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">書き方</th>
<th style="white-space: nowrap; padding: 0.2em 0.4em;">表示される内容</th>
</tr>
</thead>
<tbody>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;"><code>df.head()</code></td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">先頭5行</td>
</tr>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;"><code>df.head(3)</code></td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">先頭3行</td>
</tr>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;"><code>df.head(10)</code></td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">先頭10行。ただしデータが10行未満なら全行</td>
</tr>
</tbody>
</table></div>


<h2><span id="toc6">head()とtail()・sample()の違い</span></h2>
<p><code>head()</code> と似たメソッドとして、<code>tail()</code> と <code>sample()</code> があります。それぞれの役割を整理します。</p>


<h3><span id="toc7">head()とtail()の違い</span></h3>
<p><code>head()</code> とよく一緒に使われるのが <code>tail()</code> です。</p>
<p>違いはシンプルです。</p>
<div class="pdl-table-scroll" style="overflow-x: auto; max-width: 100%;"><table class="wp-block-table" style="width: auto; border-collapse: collapse;">
<thead>
<tr>
<th style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">メソッド</th>
<th style="white-space: nowrap; padding: 0.2em 0.4em;">表示する場所</th>
</tr>
</thead>
<tbody>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;"><code>head()</code></td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">先頭行</td>
</tr>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;"><code>tail()</code></td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">末尾行</td>
</tr>
</tbody>
</table></div>
<p>まず、<code>head()</code> で先頭を確認します。</p>


<pre class="line-numbers"><code class="language-python">df.head()</code></pre>

<div class="pdl-table-scroll" style="overflow-x: auto; max-width: 100%;">
<table class="wp-block-table" style="width: auto; border-collapse: collapse;">
  <thead>
    <tr>
      <th style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;"></th>
      <th style="white-space: nowrap; padding: 0.2em 0.4em;">注文ID</th>
      <th style="white-space: nowrap; padding: 0.2em 0.4em;">商品</th>
      <th style="white-space: nowrap; padding: 0.2em 0.4em;">カテゴリ</th>
      <th style="white-space: nowrap; padding: 0.2em 0.4em;">店舗</th>
      <th style="white-space: nowrap; padding: 0.2em 0.4em;">数量</th>
      <th style="white-space: nowrap; padding: 0.2em 0.4em;">売上</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">0</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">101</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">ノートPC</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">PC</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">東京</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">1</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">120000</td>
    </tr>
    <tr>
      <td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">1</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">102</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">マウス</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">周辺機器</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">東京</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">5</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">15000</td>
    </tr>
    <tr>
      <td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">2</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">103</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">キーボード</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">周辺機器</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">大阪</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">3</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">24000</td>
    </tr>
    <tr>
      <td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">3</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">104</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">モニター</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">周辺機器</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">大阪</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">2</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">64000</td>
    </tr>
    <tr>
      <td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">4</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">105</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">USBメモリ</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">記録媒体</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">名古屋</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">10</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">25000</td>
    </tr>
  </tbody>
</table>
</div>

<p>次に、<code>tail()</code> で末尾を確認します。</p>


<pre class="line-numbers"><code class="language-python">df.tail()</code></pre>

<div class="pdl-table-scroll" style="overflow-x: auto; max-width: 100%;">
<table class="wp-block-table" style="width: auto; border-collapse: collapse;">
  <thead>
    <tr>
      <th style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;"></th>
      <th style="white-space: nowrap; padding: 0.2em 0.4em;">注文ID</th>
      <th style="white-space: nowrap; padding: 0.2em 0.4em;">商品</th>
      <th style="white-space: nowrap; padding: 0.2em 0.4em;">カテゴリ</th>
      <th style="white-space: nowrap; padding: 0.2em 0.4em;">店舗</th>
      <th style="white-space: nowrap; padding: 0.2em 0.4em;">数量</th>
      <th style="white-space: nowrap; padding: 0.2em 0.4em;">売上</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">3</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">104</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">モニター</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">周辺機器</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">大阪</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">2</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">64000</td>
    </tr>
    <tr>
      <td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">4</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">105</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">USBメモリ</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">記録媒体</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">名古屋</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">10</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">25000</td>
    </tr>
    <tr>
      <td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">5</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">106</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">ノートPC</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">PC</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">東京</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">1</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">115000</td>
    </tr>
    <tr>
      <td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">6</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">107</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">マウス</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">周辺機器</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">名古屋</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">4</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">11200</td>
    </tr>
    <tr>
      <td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">7</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">108</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">モニター</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">周辺機器</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">大阪</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">2</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">70000</td>
    </tr>
  </tbody>
</table>
</div>

<p><code>head()</code> は先頭5行、<code>tail()</code> は末尾5行を表示します。</p>
<p>CSVやExcelを読み込んだときは、先頭だけでなく末尾も確認すると、途中でデータが切れていないか、最後の行まで正しく読み込まれているかを確認しやすくなります。</p>
<p>たとえば、次のような流れで使えます。</p>
<pre class="line-numbers"><code class="language-python">df.head()
df.tail()
</code></pre>
<p>先頭と末尾の両方を見ることで、データ全体の読み込み状態をざっくり確認できます。</p>


<h3><span id="toc8">head()・tail()・sample()の使い分け</span></h3>
<p>DataFrameの一部を確認する方法には、<code>head()</code>、<code>tail()</code>、<code>sample()</code> があります。</p>
<p>それぞれの違いは次のとおりです。</p>
<div class="pdl-table-scroll" style="overflow-x: auto; max-width: 100%;"><table class="wp-block-table" style="width: auto; border-collapse: collapse;">
<thead>
<tr>
<th style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">メソッド</th>
<th style="white-space: nowrap; padding: 0.2em 0.4em;">役割</th>
<th style="white-space: nowrap; padding: 0.2em 0.4em;">使う場面</th>
</tr>
</thead>
<tbody>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;"><code>head()</code></td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">先頭行を表示</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">読み込み直後にデータの形を確認したい</td>
</tr>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;"><code>tail()</code></td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">末尾行を表示</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">最後まで正しく読み込まれているか確認したい</td>
</tr>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;"><code>sample()</code></td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">ランダムに行を表示</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">データ全体から偏りなく数行を見たい</td>
</tr>
</tbody>
</table></div>
<p><code>sample()</code> は、DataFrameからランダムに行を取り出すメソッドです。</p>


<pre class="line-numbers"><code class="language-python">df.sample(3, random_state=0)</code></pre>

<div class="pdl-table-scroll" style="overflow-x: auto; max-width: 100%;">
<table class="wp-block-table" style="width: auto; border-collapse: collapse;">
  <thead>
    <tr>
      <th style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;"></th>
      <th style="white-space: nowrap; padding: 0.2em 0.4em;">注文ID</th>
      <th style="white-space: nowrap; padding: 0.2em 0.4em;">商品</th>
      <th style="white-space: nowrap; padding: 0.2em 0.4em;">カテゴリ</th>
      <th style="white-space: nowrap; padding: 0.2em 0.4em;">店舗</th>
      <th style="white-space: nowrap; padding: 0.2em 0.4em;">数量</th>
      <th style="white-space: nowrap; padding: 0.2em 0.4em;">売上</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">6</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">107</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">マウス</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">周辺機器</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">名古屋</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">4</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">11200</td>
    </tr>
    <tr>
      <td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">2</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">103</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">キーボード</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">周辺機器</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">大阪</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">3</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">24000</td>
    </tr>
    <tr>
      <td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">1</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">102</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">マウス</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">周辺機器</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">東京</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">5</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">15000</td>
    </tr>
  </tbody>
</table>
</div>

<p><code>head()</code> は先頭だけを見るため、データが並び順に偏っている場合は全体像をつかみにくいことがあります。</p>
<p>そのようなときは、<code>sample()</code> でランダムに数行を確認すると、より全体の雰囲気をつかみやすくなります。</p>
<p>ただし、初心者のうちはまず次の順番で十分です。</p>
<ol>
<li><code>df.head()</code> で先頭を確認</li>
<li><code>df.tail()</code> で末尾を確認</li>
<li>必要に応じて <code>df.sample()</code> でランダムに確認</li>
</ol>


<h2><span id="toc9">CSVを読み込んだあとにhead()で確認する流れ</span></h2>
<p>実際の作業では、CSVを読み込んだ直後に <code>head()</code> を使うことが多いです。</p>
<p>基本の流れは次のとおりです。</p>
<pre class="line-numbers"><code class="language-python">df = pd.read_csv("sample.csv")
df.head()
</code></pre>
<p>ここでは、CSV読み込み後の確認イメージとして、作成済みのDataFrameを使って流れを確認します。</p>


<pre class="line-numbers"><code class="language-python"># 実際には次のようにCSVを読み込むことが多いです
# df = pd.read_csv("sample.csv")

df.head()</code></pre>

<div class="pdl-table-scroll" style="overflow-x: auto; max-width: 100%;">
<table class="wp-block-table" style="width: auto; border-collapse: collapse;">
  <thead>
    <tr>
      <th style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;"></th>
      <th style="white-space: nowrap; padding: 0.2em 0.4em;">注文ID</th>
      <th style="white-space: nowrap; padding: 0.2em 0.4em;">商品</th>
      <th style="white-space: nowrap; padding: 0.2em 0.4em;">カテゴリ</th>
      <th style="white-space: nowrap; padding: 0.2em 0.4em;">店舗</th>
      <th style="white-space: nowrap; padding: 0.2em 0.4em;">数量</th>
      <th style="white-space: nowrap; padding: 0.2em 0.4em;">売上</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">0</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">101</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">ノートPC</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">PC</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">東京</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">1</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">120000</td>
    </tr>
    <tr>
      <td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">1</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">102</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">マウス</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">周辺機器</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">東京</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">5</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">15000</td>
    </tr>
    <tr>
      <td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">2</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">103</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">キーボード</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">周辺機器</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">大阪</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">3</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">24000</td>
    </tr>
    <tr>
      <td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">3</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">104</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">モニター</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">周辺機器</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">大阪</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">2</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">64000</td>
    </tr>
    <tr>
      <td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">4</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">105</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">USBメモリ</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">記録媒体</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">名古屋</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">10</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">25000</td>
    </tr>
  </tbody>
</table>
</div>

<p>CSVを読み込んだあとに <code>head()</code> を使うと、次の点を確認できます。</p>
<div class="pdl-table-scroll" style="overflow-x: auto; max-width: 100%;"><table class="wp-block-table" style="width: auto; border-collapse: collapse;">
<thead>
<tr>
<th style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">確認すること</th>
<th style="white-space: nowrap; padding: 0.2em 0.4em;">見るポイント</th>
</tr>
</thead>
<tbody>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">列名</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">文字化けや余計な空白がないか</td>
</tr>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">データ型の雰囲気</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">数値として読まれているか、文字列になっていないか</td>
</tr>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">欠損値</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;"><code>NaN</code> が不自然に出ていないか</td>
</tr>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">区切り文字</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">1列に全部入ってしまっていないか</td>
</tr>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">先頭行</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">ヘッダー行がデータとして混ざっていないか</td>
</tr>
</tbody>
</table></div>
<p><code>read_csv()</code> のあとに <code>df.head()</code> を入れる習慣をつけると、読み込みミスに早く気づけます。</p>


<h2><span id="toc10">head()の補足的な使い方</span></h2>
<p>ここからは、<code>print(df.head())</code>、<code>head(0)</code>、Series、スライス、<code>iloc</code> との違いなど、実務で迷いやすい補足を整理します。</p>


<h3><span id="toc11">df.head()とprint(df.head())の違い</span></h3>
<p>Google ColabやJupyter Notebookでは、セルの最後に <code>df.head()</code> と書くだけで表形式で表示されます。</p>


<pre class="line-numbers"><code class="language-python">df.head()</code></pre>

<div class="pdl-table-scroll" style="overflow-x: auto; max-width: 100%;">
<table class="wp-block-table" style="width: auto; border-collapse: collapse;">
  <thead>
    <tr>
      <th style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;"></th>
      <th style="white-space: nowrap; padding: 0.2em 0.4em;">注文ID</th>
      <th style="white-space: nowrap; padding: 0.2em 0.4em;">商品</th>
      <th style="white-space: nowrap; padding: 0.2em 0.4em;">カテゴリ</th>
      <th style="white-space: nowrap; padding: 0.2em 0.4em;">店舗</th>
      <th style="white-space: nowrap; padding: 0.2em 0.4em;">数量</th>
      <th style="white-space: nowrap; padding: 0.2em 0.4em;">売上</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">0</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">101</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">ノートPC</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">PC</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">東京</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">1</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">120000</td>
    </tr>
    <tr>
      <td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">1</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">102</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">マウス</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">周辺機器</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">東京</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">5</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">15000</td>
    </tr>
    <tr>
      <td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">2</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">103</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">キーボード</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">周辺機器</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">大阪</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">3</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">24000</td>
    </tr>
    <tr>
      <td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">3</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">104</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">モニター</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">周辺機器</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">大阪</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">2</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">64000</td>
    </tr>
    <tr>
      <td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">4</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">105</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">USBメモリ</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">記録媒体</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">名古屋</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">10</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">25000</td>
    </tr>
  </tbody>
</table>
</div>

<p>一方、Pythonスクリプトやターミナルで実行する場合は、<code>print(df.head())</code> と書くことがあります。</p>


<pre class="line-numbers"><code class="language-python">print(df.head())</code></pre>

<pre class="colab-output"><code>   注文ID      商品  カテゴリ   店舗  数量      売上
0   101   ノートPC    PC   東京   1  120000
1   102     マウス  周辺機器   東京   5   15000
2   103   キーボード  周辺機器   大阪   3   24000
3   104    モニター  周辺機器   大阪   2   64000
4   105  USBメモリ  記録媒体  名古屋  10   25000</code></pre>

<p>Google Colabでは、基本的に <code>df.head()</code> だけで見やすく表示されます。</p>
<div class="pdl-table-scroll" style="overflow-x: auto; max-width: 100%;"><table class="wp-block-table" style="width: auto; border-collapse: collapse;">
<thead>
<tr>
<th style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">書き方</th>
<th style="white-space: nowrap; padding: 0.2em 0.4em;">向いている場面</th>
</tr>
</thead>
<tbody>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;"><code>df.head()</code></td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">Google Colab・Jupyter Notebook</td>
</tr>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;"><code>print(df.head())</code></td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">Pythonスクリプト・ターミナル</td>
</tr>
</tbody>
</table></div>
<p>初心者がColabで学習している場合は、まず <code>df.head()</code> だけで十分です。</p>


<h3><span id="toc12">head(0)でカラム名だけ確認する</span></h3>
<p><code>df.head(0)</code> と書くと、行データは表示せず、列名だけを確認できます。</p>


<pre class="line-numbers"><code class="language-python">df.head(0)</code></pre>

<div class="pdl-table-scroll" style="overflow-x: auto; max-width: 100%;">
<table class="wp-block-table" style="width: auto; border-collapse: collapse;">
  <thead>
    <tr>
      <th style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;"></th>
      <th style="white-space: nowrap; padding: 0.2em 0.4em;">注文ID</th>
      <th style="white-space: nowrap; padding: 0.2em 0.4em;">商品</th>
      <th style="white-space: nowrap; padding: 0.2em 0.4em;">カテゴリ</th>
      <th style="white-space: nowrap; padding: 0.2em 0.4em;">店舗</th>
      <th style="white-space: nowrap; padding: 0.2em 0.4em;">数量</th>
      <th style="white-space: nowrap; padding: 0.2em 0.4em;">売上</th>
    </tr>
  </thead>
  <tbody>
  </tbody>
</table>
</div>

<p><code>head(0)</code> は、データの中身ではなく、列名だけを確認したいときに使えます。</p>
<p>たとえば、列数が多いデータで、どんなカラムがあるかだけ見たい場合に便利です。</p>
<p>ただし、列名だけ確認するなら、次のように <code>df.columns</code> を使う方法もあります。</p>


<pre class="line-numbers"><code class="language-python">df.columns</code></pre>

<div class="pdl-table-scroll" style="overflow-x: auto; max-width: 100%;">
<table class="wp-block-table" style="width: auto; border-collapse: collapse;">
  <thead>
    <tr>
      <th style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;"></th>
      <th style="white-space: nowrap; padding: 0.2em 0.4em;"></th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">0</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">注文ID</td>
    </tr>
    <tr>
      <td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">1</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">商品</td>
    </tr>
    <tr>
      <td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">2</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">カテゴリ</td>
    </tr>
    <tr>
      <td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">3</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">店舗</td>
    </tr>
    <tr>
      <td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">4</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">数量</td>
    </tr>
    <tr>
      <td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">5</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">売上</td>
    </tr>
  </tbody>
</table>
</div>

<p><code>head(0)</code> は表の形を保ったまま列名を確認したいとき、<code>df.columns</code> は列名の一覧を確認したいときに使いやすいです。</p>


<h3><span id="toc13">Seriesでもhead()は使える</span></h3>
<p><code>head()</code> はDataFrameだけでなく、Seriesにも使えます。</p>
<p>Seriesとは、DataFrameの1列を取り出したようなデータです。</p>
<p>たとえば、<code>売上</code> 列だけを取り出して <code>head()</code> を使ってみます。</p>


<pre class="line-numbers"><code class="language-python">df["売上"].head()</code></pre>

<div class="pdl-table-scroll" style="overflow-x: auto; max-width: 100%;">
<table class="wp-block-table" style="width: auto; border-collapse: collapse;">
  <thead>
    <tr>
      <th style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;"></th>
      <th style="white-space: nowrap; padding: 0.2em 0.4em;">売上</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">0</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">120000</td>
    </tr>
    <tr>
      <td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">1</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">15000</td>
    </tr>
    <tr>
      <td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">2</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">24000</td>
    </tr>
    <tr>
      <td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">3</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">64000</td>
    </tr>
    <tr>
      <td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">4</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">25000</td>
    </tr>
  </tbody>
</table>
</div>

<p>Seriesに対して <code>head()</code> を使うと、そのSeriesの先頭5件が表示されます。</p>
<p>もちろん、行数指定もできます。</p>


<pre class="line-numbers"><code class="language-python">df["売上"].head(3)</code></pre>

<div class="pdl-table-scroll" style="overflow-x: auto; max-width: 100%;">
<table class="wp-block-table" style="width: auto; border-collapse: collapse;">
  <thead>
    <tr>
      <th style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;"></th>
      <th style="white-space: nowrap; padding: 0.2em 0.4em;">売上</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">0</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">120000</td>
    </tr>
    <tr>
      <td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">1</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">15000</td>
    </tr>
    <tr>
      <td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">2</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">24000</td>
    </tr>
  </tbody>
</table>
</div>

<p>DataFrameでもSeriesでも、<code>head()</code> の基本的な考え方は同じです。</p>
<div class="pdl-table-scroll" style="overflow-x: auto; max-width: 100%;"><table class="wp-block-table" style="width: auto; border-collapse: collapse;">
<thead>
<tr>
<th style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">対象</th>
<th style="white-space: nowrap; padding: 0.2em 0.4em;">書き方</th>
<th style="white-space: nowrap; padding: 0.2em 0.4em;">結果</th>
</tr>
</thead>
<tbody>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">DataFrame</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;"><code>df.head()</code></td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">表全体の先頭5行</td>
</tr>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">Series</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;"><code>df["売上"].head()</code></td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">売上列の先頭5件</td>
</tr>
</tbody>
</table></div>


<h3><span id="toc14">スライスで先頭行を確認する方法との違い</span></h3>
<p><code>head()</code> と似たことは、スライスでもできます。</p>
<p>たとえば、先頭3行を表示する場合、次の2つは近い結果になります。</p>


<pre class="line-numbers"><code class="language-python">df.head(3)</code></pre>

<div class="pdl-table-scroll" style="overflow-x: auto; max-width: 100%;">
<table class="wp-block-table" style="width: auto; border-collapse: collapse;">
  <thead>
    <tr>
      <th style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;"></th>
      <th style="white-space: nowrap; padding: 0.2em 0.4em;">注文ID</th>
      <th style="white-space: nowrap; padding: 0.2em 0.4em;">商品</th>
      <th style="white-space: nowrap; padding: 0.2em 0.4em;">カテゴリ</th>
      <th style="white-space: nowrap; padding: 0.2em 0.4em;">店舗</th>
      <th style="white-space: nowrap; padding: 0.2em 0.4em;">数量</th>
      <th style="white-space: nowrap; padding: 0.2em 0.4em;">売上</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">0</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">101</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">ノートPC</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">PC</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">東京</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">1</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">120000</td>
    </tr>
    <tr>
      <td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">1</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">102</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">マウス</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">周辺機器</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">東京</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">5</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">15000</td>
    </tr>
    <tr>
      <td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">2</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">103</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">キーボード</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">周辺機器</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">大阪</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">3</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">24000</td>
    </tr>
  </tbody>
</table>
</div>

<pre class="line-numbers"><code class="language-python">df[:3]</code></pre>

<div class="pdl-table-scroll" style="overflow-x: auto; max-width: 100%;">
<table class="wp-block-table" style="width: auto; border-collapse: collapse;">
  <thead>
    <tr>
      <th style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;"></th>
      <th style="white-space: nowrap; padding: 0.2em 0.4em;">注文ID</th>
      <th style="white-space: nowrap; padding: 0.2em 0.4em;">商品</th>
      <th style="white-space: nowrap; padding: 0.2em 0.4em;">カテゴリ</th>
      <th style="white-space: nowrap; padding: 0.2em 0.4em;">店舗</th>
      <th style="white-space: nowrap; padding: 0.2em 0.4em;">数量</th>
      <th style="white-space: nowrap; padding: 0.2em 0.4em;">売上</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">0</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">101</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">ノートPC</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">PC</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">東京</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">1</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">120000</td>
    </tr>
    <tr>
      <td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">1</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">102</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">マウス</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">周辺機器</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">東京</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">5</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">15000</td>
    </tr>
    <tr>
      <td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">2</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">103</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">キーボード</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">周辺機器</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">大阪</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">3</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">24000</td>
    </tr>
  </tbody>
</table>
</div>

<p>どちらも先頭3行を表示できます。</p>
<p>ただし、初心者には <code>df.head(3)</code> の方が意味がわかりやすいです。</p>
<div class="pdl-table-scroll" style="overflow-x: auto; max-width: 100%;"><table class="wp-block-table" style="width: auto; border-collapse: collapse;">
<thead>
<tr>
<th style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">書き方</th>
<th style="white-space: nowrap; padding: 0.2em 0.4em;">特徴</th>
</tr>
</thead>
<tbody>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;"><code>df.head(3)</code></td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">「先頭3行を表示する」と読みやすい</td>
</tr>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;"><code>df[:3]</code></td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">Pythonのスライス記法に慣れている人向け</td>
</tr>
</tbody>
</table></div>
<p>データ確認の目的なら、まずは <code>head()</code> を使えば十分です。</p>


<h3><span id="toc15">先頭1行だけ確認する・値を取り出す場合</span></h3>
<p>先頭1行だけ確認したい場合は、<code>df.head(1)</code> を使います。</p>


<pre class="line-numbers"><code class="language-python">df.head(1)</code></pre>

<div class="pdl-table-scroll" style="overflow-x: auto; max-width: 100%;">
<table class="wp-block-table" style="width: auto; border-collapse: collapse;">
  <thead>
    <tr>
      <th style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;"></th>
      <th style="white-space: nowrap; padding: 0.2em 0.4em;">注文ID</th>
      <th style="white-space: nowrap; padding: 0.2em 0.4em;">商品</th>
      <th style="white-space: nowrap; padding: 0.2em 0.4em;">カテゴリ</th>
      <th style="white-space: nowrap; padding: 0.2em 0.4em;">店舗</th>
      <th style="white-space: nowrap; padding: 0.2em 0.4em;">数量</th>
      <th style="white-space: nowrap; padding: 0.2em 0.4em;">売上</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">0</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">101</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">ノートPC</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">PC</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">東京</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">1</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">120000</td>
    </tr>
  </tbody>
</table>
</div>

<p>ただし、<code>head()</code> は基本的には<strong>表示して確認するためのメソッド</strong>です。</p>
<p>先頭行の値を取り出して計算や処理に使いたい場合は、<code>iloc</code> を使う方が自然です。</p>


<pre class="line-numbers"><code class="language-python">df.iloc[0]</code></pre>

<div class="pdl-table-scroll" style="overflow-x: auto; max-width: 100%;">
<table class="wp-block-table" style="width: auto; border-collapse: collapse;">
  <thead>
    <tr>
      <th style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;"></th>
      <th style="white-space: nowrap; padding: 0.2em 0.4em;">0</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">注文ID</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">101</td>
    </tr>
    <tr>
      <td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">商品</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">ノートPC</td>
    </tr>
    <tr>
      <td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">カテゴリ</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">PC</td>
    </tr>
    <tr>
      <td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">店舗</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">東京</td>
    </tr>
    <tr>
      <td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">数量</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">1</td>
    </tr>
    <tr>
      <td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">売上</td>
      <td style="white-space: nowrap; padding: 0.2em 0.4em;">120000</td>
    </tr>
  </tbody>
</table>
</div>

<p><code>df.iloc[0]</code> は、DataFrameの先頭行をSeriesとして取り出します。</p>
<div class="pdl-table-scroll" style="overflow-x: auto; max-width: 100%;"><table class="wp-block-table" style="width: auto; border-collapse: collapse;">
<thead>
<tr>
<th style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">やりたいこと</th>
<th style="white-space: nowrap; padding: 0.2em 0.4em;">書き方</th>
</tr>
</thead>
<tbody>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">先頭1行を表として表示したい</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;"><code>df.head(1)</code></td>
</tr>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">先頭行をデータとして取り出したい</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;"><code>df.iloc[0]</code></td>
</tr>
</tbody>
</table></div>
<p>初心者のうちは、画面で確認するなら <code>head()</code>、値を取り出すなら <code>iloc</code> と分けて考えるとわかりやすいです。</p>


<h2><span id="toc16">よくあるミス</span></h2>
<h3><span id="toc17">df.head()を書いても全データが表示されると思ってしまう</span></h3>
<p><code>df.head()</code> は、標準では先頭5行だけを表示します。</p>
<p>全データを表示するメソッドではありません。</p>
<h3><span id="toc18">df.head(10)で必ず10行表示されると思ってしまう</span></h3>
<p>DataFrameに10行未満しかない場合は、存在する行だけが表示されます。</p>
<h3><span id="toc19">tail()との違いを混同する</span></h3>
<p><code>head()</code> は先頭行、<code>tail()</code> は末尾行です。</p>
<div class="pdl-table-scroll" style="overflow-x: auto; max-width: 100%;"><table class="wp-block-table" style="width: auto; border-collapse: collapse;">
<thead>
<tr>
<th style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">メソッド</th>
<th style="white-space: nowrap; padding: 0.2em 0.4em;">表示する行</th>
</tr>
</thead>
<tbody>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;"><code>head()</code></td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">先頭</td>
</tr>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;"><code>tail()</code></td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">末尾</td>
</tr>
</tbody>
</table></div>
<h3><span id="toc20">print(df.head())を毎回使う必要があると思ってしまう</span></h3>
<p>Google ColabやJupyter Notebookでは、セルの最後に <code>df.head()</code> と書くだけで表示できます。</p>
<p>Pythonスクリプトで実行する場合は、<code>print(df.head())</code> を使うことがあります。</p>
<h3><span id="toc21">head()だけ見てデータ全体を判断してしまう</span></h3>
<p><code>head()</code> は先頭だけを表示します。</p>
<p>データが並び順に偏っている場合、先頭だけでは全体像を誤解することがあります。</p>
<p>必要に応じて、<code>tail()</code> や <code>sample()</code> も使いましょう。</p>
<h3><span id="toc22">head()で値を取り出そうとしてしまう</span></h3>
<p><code>head()</code> は、基本的には先頭行を画面で確認するためのメソッドです。</p>
<p>先頭行そのものを取り出して処理したい場合は、<code>df.iloc[0]</code> を使う方が自然です。</p>


<h2><span id="toc23">実務でのおすすめ確認手順</span></h2>
<p>CSVやExcelを読み込んだあと、最初に何を確認すればよいかわからない場合は、次の順番がおすすめです。</p>
<pre class="line-numbers"><code class="language-python">df.head()
df.tail()
df.info()
df.describe()
</code></pre>
<p>それぞれの役割は次のとおりです。</p>
<div class="pdl-table-scroll" style="overflow-x: auto; max-width: 100%;"><table class="wp-block-table" style="width: auto; border-collapse: collapse;">
<thead>
<tr>
<th style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">手順</th>
<th style="white-space: nowrap; padding: 0.2em 0.4em;">使うメソッド</th>
<th style="white-space: nowrap; padding: 0.2em 0.4em;">確認すること</th>
</tr>
</thead>
<tbody>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">1</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;"><code>head()</code></td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">先頭行、列名、読み込み状態</td>
</tr>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">2</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;"><code>tail()</code></td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">末尾まで正しく読み込めているか</td>
</tr>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">3</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;"><code>info()</code></td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">データ型、欠損値、行数</td>
</tr>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">4</td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;"><code>describe()</code></td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">数値列の統計量</td>
</tr>
</tbody>
</table></div>
<p><code>head()</code> は、データ確認の最初の一歩です。</p>
<p>その後、<code>info()</code> や <code>describe()</code> に進むと、データの構造や統計量をより詳しく確認できます。</p>


<h2><span id="toc24">まとめ</span></h2>
<p>この記事では、<code>pandas</code> の <code>head()</code> の使い方を解説しました。</p>
<p>重要なポイントは次のとおりです。</p>
<div class="pdl-table-scroll" style="overflow-x: auto; max-width: 100%;"><table class="wp-block-table" style="width: auto; border-collapse: collapse;">
<thead>
<tr>
<th style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;">書き方</th>
<th style="white-space: nowrap; padding: 0.2em 0.4em;">意味</th>
</tr>
</thead>
<tbody>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;"><code>df.head()</code></td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">DataFrameの先頭5行を表示</td>
</tr>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;"><code>df.head(n)</code></td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">DataFrameの先頭n行を表示</td>
</tr>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;"><code>df.tail()</code></td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">DataFrameの末尾5行を表示</td>
</tr>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;"><code>df.sample(n)</code></td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">DataFrameからランダムにn行を表示</td>
</tr>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;"><code>df.head(0)</code></td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">行データを表示せず、列名だけ確認</td>
</tr>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;"><code>df["列名"].head()</code></td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">Seriesの先頭5件を表示</td>
</tr>
<tr>
<td style="min-width: 3em; white-space: nowrap; padding: 0.2em 0.4em;"><code>df.iloc[0]</code></td>
<td style="white-space: nowrap; padding: 0.2em 0.4em;">先頭行をSeriesとして取り出す</td>
</tr>
</tbody>
</table></div>
<p><code>head()</code> は、CSVやExcelを読み込んだ直後に、データが正しく読み込めているかを確認するための基本メソッドです。</p>
<p>最初は、次の流れを覚えておけば十分です。</p>
<pre class="line-numbers"><code class="language-python">df.head()
df.tail()
df.info()
df.describe()
</code></pre>
<p>まず <code>head()</code> で先頭を確認し、必要に応じて <code>tail()</code>、<code>sample()</code>、<code>info()</code>、<code>describe()</code> へ進みましょう。</p>


<h2><span id="toc25">次に読みたい関連記事</span></h2>
<ul>
<li><a href="https://pythondatalab.com/pandas-dataframe/" target="_blank">Pandas DataFrame入門｜作り方・基本操作をわかりやすく解説</a></li>
<li><a href="https://pythondatalab.com/google-colab-csv/" target="_blank">Google ColabでCSVを読み込む方法｜Drive連携とpandas read_csvを初心者向けに解説</a></li>
<li><a href="https://pythondatalab.com/pandas-info-describe/" target="_blank">pandas describe()の使い方｜統計量の意味・include=&#8217;all&#8217;・info()との違いを解説</a></li>
<li><a href="https://pythondatalab.com/pandas-value-counts/" target="_blank">pandas value_counts()の使い方｜件数集計・割合表示・欠損値の数え方を解説</a></li>
<li><a href="https://pythondatalab.com/pandas-filtering/" target="_blank">pandas 条件抽出（filtering）入門｜AND/OR・query関数・複数条件の指定方法</a></li>
<li><a href="https://pythondatalab.com/pandas-loc-iloc/" target="_blank">Pandas locとilocの違い｜行・列の抽出/スライス/条件指定を図解で解説</a></li>
</ul>


<h2><span id="toc26">公式ドキュメント</span></h2>
<p>詳しい仕様を確認したい場合は、pandas公式ドキュメントも参考になります。</p>
<ul>
<li><a rel="noopener" href="https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.head.html" target="_blank">pandas.DataFrame.head 公式ドキュメント</a></li>
<li><a rel="noopener" href="https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.tail.html" target="_blank">pandas.DataFrame.tail 公式ドキュメント</a></li>
<li><a rel="noopener" href="https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.sample.html" target="_blank">pandas.DataFrame.sample 公式ドキュメント</a></li>
</ul>
<!-- ▼▼▼ カテゴリから探す　 共通スタイル（カテゴリ）▼▼▼ -->
<style> .related-box { border: 2px solid #0073aa; border-radius: 10px; padding: 1em 1.2em; margin-top: 2em; background: #f8faff; } .related-box h3 { margin-top: 0; color: #0073aa; } .related-box ul { list-style-type: none; margin: 0; padding: 0; } .related-box li { margin: 0.4em 0; } .related-box a { text-decoration: none; color: #333; } .related-box a:hover { text-decoration: underline; color: #0073aa; } </style> <div class="related-box"> <h3><span id="toc27"> カテゴリから探す</span></h3> <ul>
<ul>
<li><a href="https://pythondatalab.com/category/pandas/basic/">◀ Pandas 基礎</a></li>
<li><a href="https://pythondatalab.com/category/pandas/preprocessing/">◀ Pandas 抽出・前処理</a></li>
<li><a href="https://pythondatalab.com/category/pandas/aggregation/">◀ Pandas 集計・変形</a></li>
<li><a href="https://pythondatalab.com/category/pandas/visualization/">▶ Matplotlib　可視化</a></li> </ul> </ul></div>
<!-- ▼▼▼ カテゴリから探す　共通スタイル（カテゴリ）終了▼▼▼ -->
<p style="text-align: center; margin-top: 2em;"><a href="#top">▲ ページトップへ戻る</a></p>



</div>


<div id="rank-math-faq" class="rank-math-block">
<div class="rank-math-list ">
<div id="faq-question-1781109657476" class="rank-math-list-item">
<h3 class="rank-math-question "><span id="toc28">pandasのhead()は何をするメソッドですか？</span></h3>
<div class="rank-math-answer ">

<p><code>head()</code> は、DataFrameやSeriesの先頭行を表示するメソッドです。<code>df.head()</code> と書くと、標準では先頭5行が表示されます。</p>

</div>
</div>
<div id="faq-question-1781109677336" class="rank-math-list-item">
<h3 class="rank-math-question "><span id="toc29">df.head()は何行表示しますか？</span></h3>
<div class="rank-math-answer ">

<p>何も指定しない場合は、先頭5行を表示します。表示行数を変えたい場合は、<code>df.head(10)</code> のように引数で行数を指定します。</p>

</div>
</div>
<div id="faq-question-1781109692027" class="rank-math-list-item">
<h3 class="rank-math-question "><span id="toc30">df.head(10)とは何ですか？</span></h3>
<div class="rank-math-answer ">

<p><code>df.head(10)</code> は、DataFrameの先頭10行を表示する書き方です。データが10行未満の場合は、存在する行だけが表示されます。</p>

</div>
</div>
<div id="faq-question-1781109708784" class="rank-math-list-item">
<h3 class="rank-math-question "><span id="toc31">head()とtail()の違いは何ですか？</span></h3>
<div class="rank-math-answer ">

<p><code>head()</code> は先頭行、<code>tail()</code> は末尾行を表示します。読み込み直後は、<code>head()</code> で先頭を確認し、<code>tail()</code> で最後まで読み込まれているか確認すると便利です。</p>

</div>
</div>
<div id="faq-question-1781109725040" class="rank-math-list-item">
<h3 class="rank-math-question "><span id="toc32">head()とsample()はどう使い分けますか？</span></h3>
<div class="rank-math-answer ">

<p><code>head()</code> は先頭行を表示し、<code>sample()</code> はランダムに行を表示します。データの先頭だけ確認したいときは <code>head()</code>、全体から偏りなく数行を見たいときは <code>sample()</code> が向いています。</p>

</div>
</div>
<div id="faq-question-1781109744161" class="rank-math-list-item">
<h3 class="rank-math-question "><span id="toc33">Seriesにもhead()は使えますか？</span></h3>
<div class="rank-math-answer ">

<p>はい。<code>df["売上"].head()</code> のように、Seriesにも <code>head()</code> を使えます。Seriesの場合は、その列の先頭5件が表示されます。</p>

</div>
</div>
<div id="faq-question-1781109764928" class="rank-math-list-item">
<h3 class="rank-math-question "><span id="toc34">Google Colabではprint(df.head())が必要ですか？</span></h3>
<div class="rank-math-answer ">

<p>通常は不要です。Google ColabやJupyter Notebookでは、セルの最後に <code>df.head()</code> と書くだけで表形式で表示されます。Pythonスクリプトで実行する場合は、<code>print(df.head())</code> を使うことがあります。</p>

</div>
</div>
<div id="faq-question-1781109781336" class="rank-math-list-item">
<h3 class="rank-math-question "><span id="toc35">head(0)は何に使いますか？</span></h3>
<div class="rank-math-answer ">

<p><code>df.head(0)</code> は、行データを表示せずに列名だけ確認したいときに使えます。列数が多いDataFrameで、カラム構成だけ確認したい場合に便利です。</p>

</div>
</div>
<div id="faq-question-1781109799864" class="rank-math-list-item">
<h3 class="rank-math-question "><span id="toc36">先頭1行だけ表示するにはどうすればよいですか？</span></h3>
<div class="rank-math-answer ">

<p><code>df.head(1)</code> と書くと、先頭1行だけを表示できます。表として確認したい場合は <code>df.head(1)</code>、先頭行の値を取り出したい場合は <code>df.iloc[0]</code> を使うとよいです。</p>

</div>
</div>
</div>
</div><p>&lt;p&gt;The post <a rel="nofollow" href="https://pythondatalab.com/pandas-head/">pandas head()の使い方｜df.head()で先頭5行を表示・tail()との違いも解説</a> first appeared on <a rel="nofollow" href="https://pythondatalab.com">Python Data Lab（Pythonデータラボ）</a>.&lt;/p&gt;</p>
]]></content:encoded>
					
					<wfw:commentRss>https://pythondatalab.com/pandas-head/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Pandas DataFrame入門｜作り方と基本操作を初心者向けに解説</title>
		<link>https://pythondatalab.com/pandas-dataframe/</link>
					<comments>https://pythondatalab.com/pandas-dataframe/#respond</comments>
		
		<dc:creator><![CDATA[coin_collector]]></dc:creator>
		<pubDate>Sun, 30 Mar 2025 14:51:24 +0000</pubDate>
				<category><![CDATA[基礎]]></category>
		<guid isPermaLink="false">https://pythondatalab.com/?p=636</guid>

					<description><![CDATA[<p>Pandas の DataFrame（データフレーム） は、Python で表形式データを扱うときの「土台」となるデータ構造です。 CSV や Excel、データベースなどから読み込んだデータは、まず DataFrame [&#8230;]</p>
<p>&lt;p&gt;The post <a rel="nofollow" href="https://pythondatalab.com/pandas-dataframe/">Pandas DataFrame入門｜作り方と基本操作を初心者向けに解説</a> first appeared on <a rel="nofollow" href="https://pythondatalab.com">Python Data Lab（Pythonデータラボ）</a>.&lt;/p&gt;</p>
]]></description>
										<content:encoded><![CDATA[
<div class="colab-article">

<p>
  Pandas の <strong>DataFrame（データフレーム）</strong> は、Python で表形式データを扱うときの「土台」となるデータ構造です。
  CSV や Excel、データベースなどから読み込んだデータは、まず DataFrame に載せてから
  前処理・集計・可視化・機械学習へと進んでいきます。
</p>

<p>
  ただ、初めて触るときは次のようなところでつまずきがちです。
</p>

<ul>
  <li>Excel の表と何が違うのか、イメージがつかみにくい</li>
  <li>リスト・辞書・NumPy 配列など、<strong>作り方が多すぎて混乱する</strong></li>
  <li>Series と DataFrame の違いがあいまいなまま進んでしまう</li>
  <li><code>[]</code> と <code>[[]]</code>、<code>loc</code> と <code>iloc</code> の違いが分からない</li>
</ul>

<div class="article-goal-box" style="border: 2px solid #4caf50; padding: 1em; border-radius: 6px; background: #f7fffb; margin: 1.5em 0;">
  <p><strong>✅ この記事のゴール</strong></p>
  <ul>
    <li><strong>DataFrame の構造</strong>（値・列名・インデックス・<code>values</code>）を図解でイメージできるようになる</li>
    <li>リスト／辞書／辞書のリスト／NumPy 配列／CSV からの<strong>5種類の作り方</strong>を自力で書けるようになる</li>
    <li><code>[]</code>・<code>[[]]</code>・<code>loc</code>・<code>iloc</code> の違いを迷わず使い分けられるようになる</li>
    <li>実務の最初の一歩で使う <strong>基本操作10個</strong>（<code>head</code> / <code>info</code> など）がひと通り身につく</li>
  </ul>
</div>


  <div id="toc" class="toc tnt-number toc-center tnt-number border-element"><input type="checkbox" class="toc-checkbox" id="toc-checkbox-5" checked><label class="toc-title" for="toc-checkbox-5">目次</label>
    <div class="toc-content">
    <ol class="toc-list open"><li><a href="#toc1" tabindex="0">【この記事で学べること】</a></li><li><a href="#toc2" tabindex="0">前提：Pandasのインストールとインポート</a></li><li><a href="#toc3" tabindex="0">Pandas DataFrame入門：全体像をつかむ</a><ol><li><a href="#toc4" tabindex="0">pandas dataframeとは？：データ分析の中心となる表形式データ</a></li><li><a href="#toc5" tabindex="0">Pandas DataFrame の基本構造を図でイメージする</a></li><li><a href="#toc6" tabindex="0">内部構造をもう少しだけ深く：values・axes・dtypes</a></li><li><a href="#toc7" tabindex="0">よく使う属性：shape / columns / index / dtypes</a></li></ol></li><li><a href="#toc8" tabindex="0">Pandas DataFrame の作り方（生成方法）</a><ol><li><a href="#toc9" tabindex="0">1. リストのリストから作成する</a></li><li><a href="#toc10" tabindex="0">2. 辞書のリストから作成する（実務でよく使うパターン）</a></li><li><a href="#toc11" tabindex="0">3. 辞書から作成する（列ごとにデータがまとまっている場合）</a></li><li><a href="#toc12" tabindex="0">4. NumPy配列から作成する</a></li><li><a href="#toc13" tabindex="0">5. インデックスを指定して作成・変更する</a></li><li><a href="#toc14" tabindex="0">6. CSVファイルなど外部ファイルから作成する</a></li></ol></li><li><a href="#toc15" tabindex="0">Pandas DataFrame と Series の違いを徹底理解</a><ol><li><a href="#toc16" tabindex="0">Seriesとは？：DataFrameの「1列」を表す1次元データ構造</a></li><li><a href="#toc17" tabindex="0">Seriesの基本的な作り方</a></li><li><a href="#toc18" tabindex="0">Series と DataFrame の決定的な違い（構造・次元・操作）</a></li></ol></li><li><a href="#toc19" tabindex="0">初心者が必ずつまずく「[] と [[]] の違い」</a></li><li><a href="#toc20" tabindex="0">最初に覚えたい10個の基本操作（DataFrame版チェックリスト）</a></li><li><a href="#toc21" tabindex="0">ミニ演習：DataFrameの基本操作を手を動かして確認しよう</a><ol><li><a href="#toc22" tabindex="0">解答例（一例）</a></li></ol></li><li><a href="#toc23" tabindex="0">実務で最初に覚えるべき DataFrame 操作10個（完全チェックリスト）</a></li><li><a href="#toc24" tabindex="0">✅ まとめ：DataFrameはPandas学習の「土台」</a></li><li><a href="#toc25" tabindex="0">関連記事：Pandasデータ分析の次のステップ</a></li><li><a href="#toc26" tabindex="0">Zenn・Qiitaでも要点まとめています</a><ol><li><a href="#toc27" tabindex="0">Q1. DataFrame と Excel の表は何が違いますか？</a></li><li><a href="#toc28" tabindex="0">Q2. DataFrame を作ったあと、まず何を確認すればいいですか？</a></li><li><a href="#toc29" tabindex="0">Q3. DataFrameの行・列の抽出はどこで学べばいいですか？</a></li><li><a href="#toc30" tabindex="0">Q4. 列名を変更したいときはどうすればいいですか？</a></li><li><a href="#toc31" tabindex="0">Q5. 数値の列が object 型（文字列）になってしまいました…</a></li><li><a href="#toc32" tabindex="0">Q6. DataFrameをExcelやCSVに保存するには？</a></li><li><a href="#toc33" tabindex="0">Q7. DataFrameの処理が遅いときはどうすればいいですか？</a></li><li><a href="#toc34" tabindex="0">Q8. DataFrameをコピーするときに注意することは？</a></li></ol></li></ol>
    </div>
  </div>

<h2><span id="toc1">【この記事で学べること】</span></h2>
<ul>
  <li>Pandas DataFrame とは何か？（Excel／スプレッドシートとの違い）</li>
  <li>DataFrame の基本構造（データ本体・列名・インデックス・<code>values</code>・<code>axes</code>）</li>
  <li>リスト／辞書／辞書のリスト／NumPy 配列／CSV から DataFrame を作成する 5 通りの方法</li>
  <li>Series と DataFrame の違いを直感的に理解するポイント</li>
  <li>初心者がよくつまずく <code>[]</code> と <code>[[]]</code> の違いと、その対処法</li>
  <li><code>head</code> / <code>info</code> / <code>loc</code> / <code>iloc</code> など、最初に覚えたい基本操作 10 個</li>
  <li>実務でよく出てくる疑問をまとめた FAQ（DataFrame と Excel の違い・保存方法・型変換・コピー時の注意点など）</li>
</ul>
<p>
  「細かいメソッドを丸暗記する」のではなく、<strong>DataFrame の構造イメージ</strong>をつかむことをゴールにしています。
  ここで土台を固めておくと、今後の <code>loc</code> / <code>iloc</code>、<code>groupby</code>、<code>merge</code>、<code>concat</code>、<code>isin</code> などの理解が一気に楽になります。
</p>

<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-</p>
<p>【体験談】私自身、最初にSeriesとDataFrameの違いが分からず、二重リストをSeriesに渡してエラーになったり、 [] と [[]] の違いに混乱したりしました。 「Series＝1次元、DataFrame＝2次元」という考え方と、列や行のラベル（インデックス）のイメージを持てるようになってから、Pandas全体が一気に理解しやすくなりました。</p>

<h2><span id="toc2">前提：Pandasのインストールとインポート</span></h2>
<p>まだPandasをインストールしていない場合は、まず次のコマンドを実行します。</p>

<pre class="line-numbers"><code class="language-python">
pip install pandas
</code></pre>

<p>Pythonコード内で使うときは、次のように pd という別名でインポートするのが定番です。</p>

<pre class="line-numbers"><code class="language-python">
import pandas as pd
</code></pre>

<h2><span id="toc3">Pandas DataFrame入門：全体像をつかむ</span></h2>

<h3><span id="toc4">pandas dataframeとは？：データ分析の中心となる表形式データ</span></h3>
<p>Pandas DataFrame は、行と列からなる 2次元の表形式データ構造 です。 イメージとしては「Excelの表」「スプレッドシート」に近く、1 行が 1 レコード（1件のデータ）、1 列が 1 つの項目（属性）を表します。</p>
<p>各列には「列名（カラム名）」が付き、行には「インデックス（index）」と呼ばれるラベルが付きます。 これにより、単なる配列よりも 「どのデータが何を表しているか」 をはっきりさせながら処理できるのが特徴です。</p>

<h3><span id="toc5">Pandas DataFrame の基本構造を図でイメージする</span></h3>
<p>例えば、次のようなテーブルを考えてみましょう。</p>


<figure>
    <img
      src="https://pythondatalab.com/wp-content/uploads/2025/11/dataframe-series.png"
      alt="PandasのDataFrame構造を示した図。左にIndex、上部に列名（Columns）があり、中央にデータが配置されている。"
      width="600"
      height="400"
      loading="lazy"
      decoding="async"
    />
    <figcaption>
      図：PandasのDataFrameの構造。Index（インデックス）・列名（Columns）・データの関係を示している。
    </figcaption>
  </figure>


<p>この表を DataFrame として考えると、ざっくり次のような構造になっています。</p>
<ul>
<li>縦方向（行方向）に「レコード」が並ぶ。</li>
<li>横方向（列方向）に「項目（カラム）」が並ぶ。</li>
<li>行には index 、列には columns というラベルが付く。indexはデフォルトでは0から始まる連番だが、自由な値を設定できる。</li>
<li>実際の値は values として データが保持される。</li>
</ul>
<p>コード上では、次のようにして DataFrame を扱います。</p>

<pre class="line-numbers"><code class="language-python">
data = {&#x27;ID&#x27;: [1, 2, 3, 4, 5],
        &#x27;Name&#x27;: [&#x27;Alice&#x27;, &#x27;Bob&#x27;, &#x27;Charlie&#x27;, &#x27;David&#x27;, &#x27;Eve&#x27;],
        &#x27;Age&#x27;: [24, 27, 22, 32, 29]
        }
df = pd.DataFrame(data)
display(df)
</code></pre>


  <div id="df-67b74301-bffe-42ec-8427-d6e17322f2ad" class="colab-df-container">
    <div>
<style scoped>
    .dataframe tbody tr th:only-of-type {
        vertical-align: middle;
    }

    .dataframe tbody tr th {
        vertical-align: top;
    }

    .dataframe thead th {
        text-align: right;
    }
</style>
<table class="wp-block-table">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th>ID</th>
      <th>Name</th>
      <th>Age</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>0</th>
      <td>1</td>
      <td>Alice</td>
      <td>24</td>
    </tr>
    <tr>
      <th>1</th>
      <td>2</td>
      <td>Bob</td>
      <td>27</td>
    </tr>
    <tr>
      <th>2</th>
      <td>3</td>
      <td>Charlie</td>
      <td>22</td>
    </tr>
    <tr>
      <th>3</th>
      <td>4</td>
      <td>David</td>
      <td>32</td>
    </tr>
    <tr>
      <th>4</th>
      <td>5</td>
      <td>Eve</td>
      <td>29</td>
    </tr>
  </tbody>
</table>
</div>
    <div class="colab-df-buttons">

  <div class="colab-df-container">
    <button class="colab-df-convert" onclick="convertToInteractive('df-67b74301-bffe-42ec-8427-d6e17322f2ad')"
            title="Convert this dataframe to an interactive table."
            style="display:none;">

  <svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 -960 960 960">
    <path d="M120-120v-720h720v720H120Zm60-500h600v-160H180v160Zm220 220h160v-160H400v160Zm0 220h160v-160H400v160ZM180-400h160v-160H180v160Zm440 0h160v-160H620v160ZM180-180h160v-160H180v160Zm440 0h160v-160H620v160Z"/>
  </svg>
    </button>

  <style>
    .colab-df-container {
      display:flex;
      gap: 12px;
    }

    .colab-df-convert {
      background-color: #E8F0FE;
      border: none;
      border-radius: 50%;
      cursor: pointer;
      display: none;
      fill: #1967D2;
      height: 32px;
      padding: 0 0 0 0;
      width: 32px;
    }

    .colab-df-convert:hover {
      background-color: #E2EBFA;
      box-shadow: 0px 1px 2px rgba(60, 64, 67, 0.3), 0px 1px 3px 1px rgba(60, 64, 67, 0.15);
      fill: #174EA6;
    }

    .colab-df-buttons div {
      margin-bottom: 4px;
    }

    [theme=dark] .colab-df-convert {
      background-color: #3B4455;
      fill: #D2E3FC;
    }

    [theme=dark] .colab-df-convert:hover {
      background-color: #434B5C;
      box-shadow: 0px 1px 3px 1px rgba(0, 0, 0, 0.15);
      filter: drop-shadow(0px 1px 2px rgba(0, 0, 0, 0.3));
      fill: #FFFFFF;
    }
  </style>

    <script>
      const buttonEl =
        document.querySelector('#df-67b74301-bffe-42ec-8427-d6e17322f2ad button.colab-df-convert');
      buttonEl.style.display =
        google.colab.kernel.accessAllowed ? 'block' : 'none';

      async function convertToInteractive(key) {
        const element = document.querySelector('#df-67b74301-bffe-42ec-8427-d6e17322f2ad');
        const dataTable =
          await google.colab.kernel.invokeFunction('convertToInteractive',
                                                    [key], {});
        if (!dataTable) return;

        const docLinkHtml = 'Like what you see? Visit the ' +
          '<a target="_blank" href=https://colab.research.google.com/notebooks/data_table.ipynb>data table notebook</a>'
          + ' to learn more about interactive tables.';
        element.innerHTML = '';
        dataTable['output_type'] = 'display_data';
        await google.colab.output.renderOutput(dataTable, element);
        const docLink = document.createElement('div');
        docLink.innerHTML = docLinkHtml;
        element.appendChild(docLink);
      }
    </script>
  </div>


    <div id="df-be3bff60-ac42-498d-8ccb-dc88c91ebfc9">
      <button class="colab-df-quickchart" onclick="quickchart('df-be3bff60-ac42-498d-8ccb-dc88c91ebfc9')"
                title="Suggest charts"
                style="display:none;">

<svg xmlns="http://www.w3.org/2000/svg" height="24px"viewBox="0 0 24 24"
     width="24px">
    <g>
        <path d="M19 3H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zM9 17H7v-7h2v7zm4 0h-2V7h2v10zm4 0h-2v-4h2v4z"/>
    </g>
</svg>
      </button>

<style>
  .colab-df-quickchart {
      --bg-color: #E8F0FE;
      --fill-color: #1967D2;
      --hover-bg-color: #E2EBFA;
      --hover-fill-color: #174EA6;
      --disabled-fill-color: #AAA;
      --disabled-bg-color: #DDD;
  }

  [theme=dark] .colab-df-quickchart {
      --bg-color: #3B4455;
      --fill-color: #D2E3FC;
      --hover-bg-color: #434B5C;
      --hover-fill-color: #FFFFFF;
      --disabled-bg-color: #3B4455;
      --disabled-fill-color: #666;
  }

  .colab-df-quickchart {
    background-color: var(--bg-color);
    border: none;
    border-radius: 50%;
    cursor: pointer;
    display: none;
    fill: var(--fill-color);
    height: 32px;
    padding: 0;
    width: 32px;
  }

  .colab-df-quickchart:hover {
    background-color: var(--hover-bg-color);
    box-shadow: 0 1px 2px rgba(60, 64, 67, 0.3), 0 1px 3px 1px rgba(60, 64, 67, 0.15);
    fill: var(--button-hover-fill-color);
  }

  .colab-df-quickchart-complete:disabled,
  .colab-df-quickchart-complete:disabled:hover {
    background-color: var(--disabled-bg-color);
    fill: var(--disabled-fill-color);
    box-shadow: none;
  }

  .colab-df-spinner {
    border: 2px solid var(--fill-color);
    border-color: transparent;
    border-bottom-color: var(--fill-color);
    animation:
      spin 1s steps(1) infinite;
  }

  @keyframes spin {
    0% {
      border-color: transparent;
      border-bottom-color: var(--fill-color);
      border-left-color: var(--fill-color);
    }
    20% {
      border-color: transparent;
      border-left-color: var(--fill-color);
      border-top-color: var(--fill-color);
    }
    30% {
      border-color: transparent;
      border-left-color: var(--fill-color);
      border-top-color: var(--fill-color);
      border-right-color: var(--fill-color);
    }
    40% {
      border-color: transparent;
      border-right-color: var(--fill-color);
      border-top-color: var(--fill-color);
    }
    60% {
      border-color: transparent;
      border-right-color: var(--fill-color);
    }
    80% {
      border-color: transparent;
      border-right-color: var(--fill-color);
      border-bottom-color: var(--fill-color);
    }
    90% {
      border-color: transparent;
      border-bottom-color: var(--fill-color);
    }
  }
</style>

      <script>
        async function quickchart(key) {
          const quickchartButtonEl =
            document.querySelector('#' + key + ' button');
          quickchartButtonEl.disabled = true;  // To prevent multiple clicks.
          quickchartButtonEl.classList.add('colab-df-spinner');
          try {
            const charts = await google.colab.kernel.invokeFunction(
                'suggestCharts', [key], {});
          } catch (error) {
            console.error('Error during call to suggestCharts:', error);
          }
          quickchartButtonEl.classList.remove('colab-df-spinner');
          quickchartButtonEl.classList.add('colab-df-quickchart-complete');
        }
        (() => {
          let quickchartButtonEl =
            document.querySelector('#df-be3bff60-ac42-498d-8ccb-dc88c91ebfc9 button');
          quickchartButtonEl.style.display =
            google.colab.kernel.accessAllowed ? 'block' : 'none';
        })();
      </script>
    </div>

  <div id="id_291723d4-c2a7-4124-ab3d-9b71418c3149">
    <style>
      .colab-df-generate {
        background-color: #E8F0FE;
        border: none;
        border-radius: 50%;
        cursor: pointer;
        display: none;
        fill: #1967D2;
        height: 32px;
        padding: 0 0 0 0;
        width: 32px;
      }

      .colab-df-generate:hover {
        background-color: #E2EBFA;
        box-shadow: 0px 1px 2px rgba(60, 64, 67, 0.3), 0px 1px 3px 1px rgba(60, 64, 67, 0.15);
        fill: #174EA6;
      }

      [theme=dark] .colab-df-generate {
        background-color: #3B4455;
        fill: #D2E3FC;
      }

      [theme=dark] .colab-df-generate:hover {
        background-color: #434B5C;
        box-shadow: 0px 1px 3px 1px rgba(0, 0, 0, 0.15);
        filter: drop-shadow(0px 1px 2px rgba(0, 0, 0, 0.3));
        fill: #FFFFFF;
      }
    </style>
    <button class="colab-df-generate" onclick="generateWithVariable('df')"
            title="Generate code using this dataframe."
            style="display:none;">

  <svg xmlns="http://www.w3.org/2000/svg" height="24px"viewBox="0 0 24 24"
       width="24px">
    <path d="M7,19H8.4L18.45,9,17,7.55,7,17.6ZM5,21V16.75L18.45,3.32a2,2,0,0,1,2.83,0l1.4,1.43a1.91,1.91,0,0,1,.58,1.4,1.91,1.91,0,0,1-.58,1.4L9.25,21ZM18.45,9,17,7.55Zm-12,3A5.31,5.31,0,0,0,4.9,8.1,5.31,5.31,0,0,0,1,6.5,5.31,5.31,0,0,0,4.9,4.9,5.31,5.31,0,0,0,6.5,1,5.31,5.31,0,0,0,8.1,4.9,5.31,5.31,0,0,0,12,6.5,5.46,5.46,0,0,0,6.5,12Z"/>
  </svg>
    </button>
    <script>
      (() => {
      const buttonEl =
        document.querySelector('#id_291723d4-c2a7-4124-ab3d-9b71418c3149 button.colab-df-generate');
      buttonEl.style.display =
        google.colab.kernel.accessAllowed ? 'block' : 'none';

      buttonEl.onclick = () => {
        google.colab.notebook.generateWithVariable('df');
      }
      })();
    </script>
  </div>

    </div>
  </div>


<h3><span id="toc6">内部構造をもう少しだけ深く：values・axes・dtypes</span></h3>
<p>DataFrame の中身は、ざっくり次のような属性で確認できます。</p>
<ul>
<li>df.values … 実データ</li>
<li>df.index … 行ラベル（インデックス）</li>
<li>df.columns … 列ラベル（カラム名）</li>
<li>df.dtypes … 各列のデータ型（int64, float64, object など）</li>
<li>df.axes … 行と列のラベルをまとめた情報</li>
</ul>
<p>これらを意識できるようになると、 「どの軸に沿って操作しているのか」 が分かりやすくなり、 axis=0 / axis=1 の指定なども迷いにくくなります。</p>

<h3><span id="toc7">よく使う属性：shape / columns / index / dtypes</span></h3>
<p>特に次の4つは、DataFrameを受け取った直後に確認する「健康診断」のようなものです。</p>

<pre class="line-numbers"><code class="language-python">
display(df.shape)   # (行数, 列数)
display(df.columns) # 列名の一覧
display(df.index)   # 行ラベルの一覧
display(df.dtypes)  # 各列のデータ型

</code></pre>

<p>(5, 3)</p>
<p>Index([&#8216;ID&#8217;, &#8216;Name&#8217;, &#8216;Age&#8217;], dtype=&#8217;object&#8217;)</p>
<p>RangeIndex(start=0, stop=5, step=1)</p>

<div>
<style scoped>
    .dataframe tbody tr th:only-of-type {
        vertical-align: middle;
    }

    .dataframe tbody tr th {
        vertical-align: top;
    }

    .dataframe thead th {
        text-align: right;
    }
</style>
<table class="wp-block-table">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th>0</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>ID</th>
      <td>int64</td>
    </tr>
    <tr>
      <th>Name</th>
      <td>object</td>
    </tr>
    <tr>
      <th>Age</th>
      <td>int64</td>
    </tr>
  </tbody>
</table>
</div><br><label><b>dtype:</b> object</label>

<p>本格的なデータ分析に入る前に、 「どの列が数値で、どの列が文字列なのか」「行数・列数はどれくらいか」 をざっくり把握しておくと、後のトラブルを避けやすくなります。</p>

<h2><span id="toc8">Pandas DataFrame の作り方（生成方法）</span></h2>
<p>DataFrame の作り方はいくつかパターンがありますが、よく使うのは次の6つです。</p>
<ul>
<li>リストのリストから作成する</li>
<li>辞書のリストから作成する（実務でよく使うパターン）</li>
<li>辞書から作成する（列ごとにデータがまとまっている場合）</li>
<li>NumPy配列から作成する</li>
<li>インデックスを指定して作成・変更する</li>
<li>CSVファイルなど外部ファイルから作成する</li>
</ul>

<h3><span id="toc9">1. リストのリストから作成する</span></h3>

<pre class="line-numbers"><code class="language-python">
data = [[1, &#x27;Alice&#x27;, 24],
        [2, &#x27;Bob&#x27;, 27],
        [3, &#x27;Charlie&#x27;, 22],
        [4, &#x27;David&#x27;, 32],
        [5, &#x27;Eve&#x27;, 29]
        ]

# columns引数で列名を指定してDataFrameを作成
df= pd.DataFrame(data, columns=[&#x27;ID&#x27;, &#x27;Name&#x27;, &#x27;Age&#x27;])

display(df)
</code></pre>


  <div id="df-f2ee712b-5954-45dc-890c-70da5af5a2b1" class="colab-df-container">
    <div>
<style scoped>
    .dataframe tbody tr th:only-of-type {
        vertical-align: middle;
    }

    .dataframe tbody tr th {
        vertical-align: top;
    }

    .dataframe thead th {
        text-align: right;
    }
</style>
<table class="wp-block-table">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th>ID</th>
      <th>Name</th>
      <th>Age</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>0</th>
      <td>1</td>
      <td>Alice</td>
      <td>24</td>
    </tr>
    <tr>
      <th>1</th>
      <td>2</td>
      <td>Bob</td>
      <td>27</td>
    </tr>
    <tr>
      <th>2</th>
      <td>3</td>
      <td>Charlie</td>
      <td>22</td>
    </tr>
    <tr>
      <th>3</th>
      <td>4</td>
      <td>David</td>
      <td>32</td>
    </tr>
    <tr>
      <th>4</th>
      <td>5</td>
      <td>Eve</td>
      <td>29</td>
    </tr>
  </tbody>
</table>
</div>
    <div class="colab-df-buttons">

  <div class="colab-df-container">
    <button class="colab-df-convert" onclick="convertToInteractive('df-f2ee712b-5954-45dc-890c-70da5af5a2b1')"
            title="Convert this dataframe to an interactive table."
            style="display:none;">

  <svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 -960 960 960">
    <path d="M120-120v-720h720v720H120Zm60-500h600v-160H180v160Zm220 220h160v-160H400v160Zm0 220h160v-160H400v160ZM180-400h160v-160H180v160Zm440 0h160v-160H620v160ZM180-180h160v-160H180v160Zm440 0h160v-160H620v160Z"/>
  </svg>
    </button>

  <style>
    .colab-df-container {
      display:flex;
      gap: 12px;
    }

    .colab-df-convert {
      background-color: #E8F0FE;
      border: none;
      border-radius: 50%;
      cursor: pointer;
      display: none;
      fill: #1967D2;
      height: 32px;
      padding: 0 0 0 0;
      width: 32px;
    }

    .colab-df-convert:hover {
      background-color: #E2EBFA;
      box-shadow: 0px 1px 2px rgba(60, 64, 67, 0.3), 0px 1px 3px 1px rgba(60, 64, 67, 0.15);
      fill: #174EA6;
    }

    .colab-df-buttons div {
      margin-bottom: 4px;
    }

    [theme=dark] .colab-df-convert {
      background-color: #3B4455;
      fill: #D2E3FC;
    }

    [theme=dark] .colab-df-convert:hover {
      background-color: #434B5C;
      box-shadow: 0px 1px 3px 1px rgba(0, 0, 0, 0.15);
      filter: drop-shadow(0px 1px 2px rgba(0, 0, 0, 0.3));
      fill: #FFFFFF;
    }
  </style>

    <script>
      const buttonEl =
        document.querySelector('#df-f2ee712b-5954-45dc-890c-70da5af5a2b1 button.colab-df-convert');
      buttonEl.style.display =
        google.colab.kernel.accessAllowed ? 'block' : 'none';

      async function convertToInteractive(key) {
        const element = document.querySelector('#df-f2ee712b-5954-45dc-890c-70da5af5a2b1');
        const dataTable =
          await google.colab.kernel.invokeFunction('convertToInteractive',
                                                    [key], {});
        if (!dataTable) return;

        const docLinkHtml = 'Like what you see? Visit the ' +
          '<a target="_blank" href=https://colab.research.google.com/notebooks/data_table.ipynb>data table notebook</a>'
          + ' to learn more about interactive tables.';
        element.innerHTML = '';
        dataTable['output_type'] = 'display_data';
        await google.colab.output.renderOutput(dataTable, element);
        const docLink = document.createElement('div');
        docLink.innerHTML = docLinkHtml;
        element.appendChild(docLink);
      }
    </script>
  </div>


    <div id="df-582f40e4-828b-4e03-a911-9b5becf3184f">
      <button class="colab-df-quickchart" onclick="quickchart('df-582f40e4-828b-4e03-a911-9b5becf3184f')"
                title="Suggest charts"
                style="display:none;">

<svg xmlns="http://www.w3.org/2000/svg" height="24px"viewBox="0 0 24 24"
     width="24px">
    <g>
        <path d="M19 3H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zM9 17H7v-7h2v7zm4 0h-2V7h2v10zm4 0h-2v-4h2v4z"/>
    </g>
</svg>
      </button>

<style>
  .colab-df-quickchart {
      --bg-color: #E8F0FE;
      --fill-color: #1967D2;
      --hover-bg-color: #E2EBFA;
      --hover-fill-color: #174EA6;
      --disabled-fill-color: #AAA;
      --disabled-bg-color: #DDD;
  }

  [theme=dark] .colab-df-quickchart {
      --bg-color: #3B4455;
      --fill-color: #D2E3FC;
      --hover-bg-color: #434B5C;
      --hover-fill-color: #FFFFFF;
      --disabled-bg-color: #3B4455;
      --disabled-fill-color: #666;
  }

  .colab-df-quickchart {
    background-color: var(--bg-color);
    border: none;
    border-radius: 50%;
    cursor: pointer;
    display: none;
    fill: var(--fill-color);
    height: 32px;
    padding: 0;
    width: 32px;
  }

  .colab-df-quickchart:hover {
    background-color: var(--hover-bg-color);
    box-shadow: 0 1px 2px rgba(60, 64, 67, 0.3), 0 1px 3px 1px rgba(60, 64, 67, 0.15);
    fill: var(--button-hover-fill-color);
  }

  .colab-df-quickchart-complete:disabled,
  .colab-df-quickchart-complete:disabled:hover {
    background-color: var(--disabled-bg-color);
    fill: var(--disabled-fill-color);
    box-shadow: none;
  }

  .colab-df-spinner {
    border: 2px solid var(--fill-color);
    border-color: transparent;
    border-bottom-color: var(--fill-color);
    animation:
      spin 1s steps(1) infinite;
  }

  @keyframes spin {
    0% {
      border-color: transparent;
      border-bottom-color: var(--fill-color);
      border-left-color: var(--fill-color);
    }
    20% {
      border-color: transparent;
      border-left-color: var(--fill-color);
      border-top-color: var(--fill-color);
    }
    30% {
      border-color: transparent;
      border-left-color: var(--fill-color);
      border-top-color: var(--fill-color);
      border-right-color: var(--fill-color);
    }
    40% {
      border-color: transparent;
      border-right-color: var(--fill-color);
      border-top-color: var(--fill-color);
    }
    60% {
      border-color: transparent;
      border-right-color: var(--fill-color);
    }
    80% {
      border-color: transparent;
      border-right-color: var(--fill-color);
      border-bottom-color: var(--fill-color);
    }
    90% {
      border-color: transparent;
      border-bottom-color: var(--fill-color);
    }
  }
</style>

      <script>
        async function quickchart(key) {
          const quickchartButtonEl =
            document.querySelector('#' + key + ' button');
          quickchartButtonEl.disabled = true;  // To prevent multiple clicks.
          quickchartButtonEl.classList.add('colab-df-spinner');
          try {
            const charts = await google.colab.kernel.invokeFunction(
                'suggestCharts', [key], {});
          } catch (error) {
            console.error('Error during call to suggestCharts:', error);
          }
          quickchartButtonEl.classList.remove('colab-df-spinner');
          quickchartButtonEl.classList.add('colab-df-quickchart-complete');
        }
        (() => {
          let quickchartButtonEl =
            document.querySelector('#df-582f40e4-828b-4e03-a911-9b5becf3184f button');
          quickchartButtonEl.style.display =
            google.colab.kernel.accessAllowed ? 'block' : 'none';
        })();
      </script>
    </div>

  <div id="id_257a2306-dc41-456e-b9d1-aca9a98ac88c">
    <style>
      .colab-df-generate {
        background-color: #E8F0FE;
        border: none;
        border-radius: 50%;
        cursor: pointer;
        display: none;
        fill: #1967D2;
        height: 32px;
        padding: 0 0 0 0;
        width: 32px;
      }

      .colab-df-generate:hover {
        background-color: #E2EBFA;
        box-shadow: 0px 1px 2px rgba(60, 64, 67, 0.3), 0px 1px 3px 1px rgba(60, 64, 67, 0.15);
        fill: #174EA6;
      }

      [theme=dark] .colab-df-generate {
        background-color: #3B4455;
        fill: #D2E3FC;
      }

      [theme=dark] .colab-df-generate:hover {
        background-color: #434B5C;
        box-shadow: 0px 1px 3px 1px rgba(0, 0, 0, 0.15);
        filter: drop-shadow(0px 1px 2px rgba(0, 0, 0, 0.3));
        fill: #FFFFFF;
      }
    </style>
    <button class="colab-df-generate" onclick="generateWithVariable('df')"
            title="Generate code using this dataframe."
            style="display:none;">

  <svg xmlns="http://www.w3.org/2000/svg" height="24px"viewBox="0 0 24 24"
       width="24px">
    <path d="M7,19H8.4L18.45,9,17,7.55,7,17.6ZM5,21V16.75L18.45,3.32a2,2,0,0,1,2.83,0l1.4,1.43a1.91,1.91,0,0,1,.58,1.4,1.91,1.91,0,0,1-.58,1.4L9.25,21ZM18.45,9,17,7.55Zm-12,3A5.31,5.31,0,0,0,4.9,8.1,5.31,5.31,0,0,0,1,6.5,5.31,5.31,0,0,0,4.9,4.9,5.31,5.31,0,0,0,6.5,1,5.31,5.31,0,0,0,8.1,4.9,5.31,5.31,0,0,0,12,6.5,5.46,5.46,0,0,0,6.5,12Z"/>
  </svg>
    </button>
    <script>
      (() => {
      const buttonEl =
        document.querySelector('#id_257a2306-dc41-456e-b9d1-aca9a98ac88c button.colab-df-generate');
      buttonEl.style.display =
        google.colab.kernel.accessAllowed ? 'block' : 'none';

      buttonEl.onclick = () => {
        google.colab.notebook.generateWithVariable('df');
      }
      })();
    </script>
  </div>

    </div>
  </div>


<h3><span id="toc10">2. 辞書のリストから作成する（実務でよく使うパターン）</span></h3>
<p>Web API や JSON などから取得したデータは、この「辞書のリスト」形式になっていることが多いため、最も実務で登場しやすいパターンです。</p>

<pre class="line-numbers"><code class="language-python">
data = [{&#x27;ID&#x27;:1,&#x27;Name&#x27;:&#x27;Alice&#x27;,&#x27;Age&#x27;:24},
        {&#x27;ID&#x27;:2,&#x27;Name&#x27;:&#x27;Bob&#x27;,&#x27;Age&#x27;:27},
        {&#x27;ID&#x27;:3,&#x27;Name&#x27;:&#x27;Charlie&#x27;,&#x27;Age&#x27;:22},
        {&#x27;ID&#x27;:4,&#x27;Name&#x27;:&#x27;David&#x27;,&#x27;Age&#x27;:32},
        {&#x27;ID&#x27;:5,&#x27;Name&#x27;:&#x27;Eve&#x27;,&#x27;Age&#x27;:29},
        ]

df = pd.DataFrame(data)

display(df)
</code></pre>


  <div id="df-10305dac-bec5-44b2-a14e-9a870f1b2769" class="colab-df-container">
    <div>
<style scoped>
    .dataframe tbody tr th:only-of-type {
        vertical-align: middle;
    }

    .dataframe tbody tr th {
        vertical-align: top;
    }

    .dataframe thead th {
        text-align: right;
    }
</style>
<table class="wp-block-table">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th>ID</th>
      <th>Name</th>
      <th>Age</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>0</th>
      <td>1</td>
      <td>Alice</td>
      <td>24</td>
    </tr>
    <tr>
      <th>1</th>
      <td>2</td>
      <td>Bob</td>
      <td>27</td>
    </tr>
    <tr>
      <th>2</th>
      <td>3</td>
      <td>Charlie</td>
      <td>22</td>
    </tr>
    <tr>
      <th>3</th>
      <td>4</td>
      <td>David</td>
      <td>32</td>
    </tr>
    <tr>
      <th>4</th>
      <td>5</td>
      <td>Eve</td>
      <td>29</td>
    </tr>
  </tbody>
</table>
</div>
    <div class="colab-df-buttons">

  <div class="colab-df-container">
    <button class="colab-df-convert" onclick="convertToInteractive('df-10305dac-bec5-44b2-a14e-9a870f1b2769')"
            title="Convert this dataframe to an interactive table."
            style="display:none;">

  <svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 -960 960 960">
    <path d="M120-120v-720h720v720H120Zm60-500h600v-160H180v160Zm220 220h160v-160H400v160Zm0 220h160v-160H400v160ZM180-400h160v-160H180v160Zm440 0h160v-160H620v160ZM180-180h160v-160H180v160Zm440 0h160v-160H620v160Z"/>
  </svg>
    </button>

  <style>
    .colab-df-container {
      display:flex;
      gap: 12px;
    }

    .colab-df-convert {
      background-color: #E8F0FE;
      border: none;
      border-radius: 50%;
      cursor: pointer;
      display: none;
      fill: #1967D2;
      height: 32px;
      padding: 0 0 0 0;
      width: 32px;
    }

    .colab-df-convert:hover {
      background-color: #E2EBFA;
      box-shadow: 0px 1px 2px rgba(60, 64, 67, 0.3), 0px 1px 3px 1px rgba(60, 64, 67, 0.15);
      fill: #174EA6;
    }

    .colab-df-buttons div {
      margin-bottom: 4px;
    }

    [theme=dark] .colab-df-convert {
      background-color: #3B4455;
      fill: #D2E3FC;
    }

    [theme=dark] .colab-df-convert:hover {
      background-color: #434B5C;
      box-shadow: 0px 1px 3px 1px rgba(0, 0, 0, 0.15);
      filter: drop-shadow(0px 1px 2px rgba(0, 0, 0, 0.3));
      fill: #FFFFFF;
    }
  </style>

    <script>
      const buttonEl =
        document.querySelector('#df-10305dac-bec5-44b2-a14e-9a870f1b2769 button.colab-df-convert');
      buttonEl.style.display =
        google.colab.kernel.accessAllowed ? 'block' : 'none';

      async function convertToInteractive(key) {
        const element = document.querySelector('#df-10305dac-bec5-44b2-a14e-9a870f1b2769');
        const dataTable =
          await google.colab.kernel.invokeFunction('convertToInteractive',
                                                    [key], {});
        if (!dataTable) return;

        const docLinkHtml = 'Like what you see? Visit the ' +
          '<a target="_blank" href=https://colab.research.google.com/notebooks/data_table.ipynb>data table notebook</a>'
          + ' to learn more about interactive tables.';
        element.innerHTML = '';
        dataTable['output_type'] = 'display_data';
        await google.colab.output.renderOutput(dataTable, element);
        const docLink = document.createElement('div');
        docLink.innerHTML = docLinkHtml;
        element.appendChild(docLink);
      }
    </script>
  </div>


    <div id="df-0ef091f4-fae7-4642-acba-ac665d2593ad">
      <button class="colab-df-quickchart" onclick="quickchart('df-0ef091f4-fae7-4642-acba-ac665d2593ad')"
                title="Suggest charts"
                style="display:none;">

<svg xmlns="http://www.w3.org/2000/svg" height="24px"viewBox="0 0 24 24"
     width="24px">
    <g>
        <path d="M19 3H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zM9 17H7v-7h2v7zm4 0h-2V7h2v10zm4 0h-2v-4h2v4z"/>
    </g>
</svg>
      </button>

<style>
  .colab-df-quickchart {
      --bg-color: #E8F0FE;
      --fill-color: #1967D2;
      --hover-bg-color: #E2EBFA;
      --hover-fill-color: #174EA6;
      --disabled-fill-color: #AAA;
      --disabled-bg-color: #DDD;
  }

  [theme=dark] .colab-df-quickchart {
      --bg-color: #3B4455;
      --fill-color: #D2E3FC;
      --hover-bg-color: #434B5C;
      --hover-fill-color: #FFFFFF;
      --disabled-bg-color: #3B4455;
      --disabled-fill-color: #666;
  }

  .colab-df-quickchart {
    background-color: var(--bg-color);
    border: none;
    border-radius: 50%;
    cursor: pointer;
    display: none;
    fill: var(--fill-color);
    height: 32px;
    padding: 0;
    width: 32px;
  }

  .colab-df-quickchart:hover {
    background-color: var(--hover-bg-color);
    box-shadow: 0 1px 2px rgba(60, 64, 67, 0.3), 0 1px 3px 1px rgba(60, 64, 67, 0.15);
    fill: var(--button-hover-fill-color);
  }

  .colab-df-quickchart-complete:disabled,
  .colab-df-quickchart-complete:disabled:hover {
    background-color: var(--disabled-bg-color);
    fill: var(--disabled-fill-color);
    box-shadow: none;
  }

  .colab-df-spinner {
    border: 2px solid var(--fill-color);
    border-color: transparent;
    border-bottom-color: var(--fill-color);
    animation:
      spin 1s steps(1) infinite;
  }

  @keyframes spin {
    0% {
      border-color: transparent;
      border-bottom-color: var(--fill-color);
      border-left-color: var(--fill-color);
    }
    20% {
      border-color: transparent;
      border-left-color: var(--fill-color);
      border-top-color: var(--fill-color);
    }
    30% {
      border-color: transparent;
      border-left-color: var(--fill-color);
      border-top-color: var(--fill-color);
      border-right-color: var(--fill-color);
    }
    40% {
      border-color: transparent;
      border-right-color: var(--fill-color);
      border-top-color: var(--fill-color);
    }
    60% {
      border-color: transparent;
      border-right-color: var(--fill-color);
    }
    80% {
      border-color: transparent;
      border-right-color: var(--fill-color);
      border-bottom-color: var(--fill-color);
    }
    90% {
      border-color: transparent;
      border-bottom-color: var(--fill-color);
    }
  }
</style>

      <script>
        async function quickchart(key) {
          const quickchartButtonEl =
            document.querySelector('#' + key + ' button');
          quickchartButtonEl.disabled = true;  // To prevent multiple clicks.
          quickchartButtonEl.classList.add('colab-df-spinner');
          try {
            const charts = await google.colab.kernel.invokeFunction(
                'suggestCharts', [key], {});
          } catch (error) {
            console.error('Error during call to suggestCharts:', error);
          }
          quickchartButtonEl.classList.remove('colab-df-spinner');
          quickchartButtonEl.classList.add('colab-df-quickchart-complete');
        }
        (() => {
          let quickchartButtonEl =
            document.querySelector('#df-0ef091f4-fae7-4642-acba-ac665d2593ad button');
          quickchartButtonEl.style.display =
            google.colab.kernel.accessAllowed ? 'block' : 'none';
        })();
      </script>
    </div>

  <div id="id_364c49f5-6fce-4cd2-a78c-155ad3fb8413">
    <style>
      .colab-df-generate {
        background-color: #E8F0FE;
        border: none;
        border-radius: 50%;
        cursor: pointer;
        display: none;
        fill: #1967D2;
        height: 32px;
        padding: 0 0 0 0;
        width: 32px;
      }

      .colab-df-generate:hover {
        background-color: #E2EBFA;
        box-shadow: 0px 1px 2px rgba(60, 64, 67, 0.3), 0px 1px 3px 1px rgba(60, 64, 67, 0.15);
        fill: #174EA6;
      }

      [theme=dark] .colab-df-generate {
        background-color: #3B4455;
        fill: #D2E3FC;
      }

      [theme=dark] .colab-df-generate:hover {
        background-color: #434B5C;
        box-shadow: 0px 1px 3px 1px rgba(0, 0, 0, 0.15);
        filter: drop-shadow(0px 1px 2px rgba(0, 0, 0, 0.3));
        fill: #FFFFFF;
      }
    </style>
    <button class="colab-df-generate" onclick="generateWithVariable('df')"
            title="Generate code using this dataframe."
            style="display:none;">

  <svg xmlns="http://www.w3.org/2000/svg" height="24px"viewBox="0 0 24 24"
       width="24px">
    <path d="M7,19H8.4L18.45,9,17,7.55,7,17.6ZM5,21V16.75L18.45,3.32a2,2,0,0,1,2.83,0l1.4,1.43a1.91,1.91,0,0,1,.58,1.4,1.91,1.91,0,0,1-.58,1.4L9.25,21ZM18.45,9,17,7.55Zm-12,3A5.31,5.31,0,0,0,4.9,8.1,5.31,5.31,0,0,0,1,6.5,5.31,5.31,0,0,0,4.9,4.9,5.31,5.31,0,0,0,6.5,1,5.31,5.31,0,0,0,8.1,4.9,5.31,5.31,0,0,0,12,6.5,5.46,5.46,0,0,0,6.5,12Z"/>
  </svg>
    </button>
    <script>
      (() => {
      const buttonEl =
        document.querySelector('#id_364c49f5-6fce-4cd2-a78c-155ad3fb8413 button.colab-df-generate');
      buttonEl.style.display =
        google.colab.kernel.accessAllowed ? 'block' : 'none';

      buttonEl.onclick = () => {
        google.colab.notebook.generateWithVariable('df');
      }
      })();
    </script>
  </div>

    </div>
  </div>


<h3><span id="toc11">3. 辞書から作成する（列ごとにデータがまとまっている場合）</span></h3>
<p>列単位でデータが用意されているときは、辞書からの作成 がシンプルです。 辞書の「キー」が DataFrame の列名、「値」がその列のデータ（リストやNumPy配列）になります。</p>

<pre class="line-numbers"><code class="language-python">
data = {&#x27;ID&#x27;: [1, 2, 3, 4, 5],
        &#x27;Name&#x27;: [&#x27;Alice&#x27;, &#x27;Bob&#x27;, &#x27;Charlie&#x27;, &#x27;David&#x27;, &#x27;Eve&#x27;],
        &#x27;Age&#x27;: [24, 27, 22, 32, 29]
        }

df = pd.DataFrame(data)

display(df)
</code></pre>


  <div id="df-e264120c-1feb-4ffd-b466-d6506285bec4" class="colab-df-container">
    <div>
<style scoped>
    .dataframe tbody tr th:only-of-type {
        vertical-align: middle;
    }

    .dataframe tbody tr th {
        vertical-align: top;
    }

    .dataframe thead th {
        text-align: right;
    }
</style>
<table class="wp-block-table">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th>ID</th>
      <th>Name</th>
      <th>Age</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>0</th>
      <td>1</td>
      <td>Alice</td>
      <td>24</td>
    </tr>
    <tr>
      <th>1</th>
      <td>2</td>
      <td>Bob</td>
      <td>27</td>
    </tr>
    <tr>
      <th>2</th>
      <td>3</td>
      <td>Charlie</td>
      <td>22</td>
    </tr>
    <tr>
      <th>3</th>
      <td>4</td>
      <td>David</td>
      <td>32</td>
    </tr>
    <tr>
      <th>4</th>
      <td>5</td>
      <td>Eve</td>
      <td>29</td>
    </tr>
  </tbody>
</table>
</div>
    <div class="colab-df-buttons">

  <div class="colab-df-container">
    <button class="colab-df-convert" onclick="convertToInteractive('df-e264120c-1feb-4ffd-b466-d6506285bec4')"
            title="Convert this dataframe to an interactive table."
            style="display:none;">

  <svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 -960 960 960">
    <path d="M120-120v-720h720v720H120Zm60-500h600v-160H180v160Zm220 220h160v-160H400v160Zm0 220h160v-160H400v160ZM180-400h160v-160H180v160Zm440 0h160v-160H620v160ZM180-180h160v-160H180v160Zm440 0h160v-160H620v160Z"/>
  </svg>
    </button>

  <style>
    .colab-df-container {
      display:flex;
      gap: 12px;
    }

    .colab-df-convert {
      background-color: #E8F0FE;
      border: none;
      border-radius: 50%;
      cursor: pointer;
      display: none;
      fill: #1967D2;
      height: 32px;
      padding: 0 0 0 0;
      width: 32px;
    }

    .colab-df-convert:hover {
      background-color: #E2EBFA;
      box-shadow: 0px 1px 2px rgba(60, 64, 67, 0.3), 0px 1px 3px 1px rgba(60, 64, 67, 0.15);
      fill: #174EA6;
    }

    .colab-df-buttons div {
      margin-bottom: 4px;
    }

    [theme=dark] .colab-df-convert {
      background-color: #3B4455;
      fill: #D2E3FC;
    }

    [theme=dark] .colab-df-convert:hover {
      background-color: #434B5C;
      box-shadow: 0px 1px 3px 1px rgba(0, 0, 0, 0.15);
      filter: drop-shadow(0px 1px 2px rgba(0, 0, 0, 0.3));
      fill: #FFFFFF;
    }
  </style>

    <script>
      const buttonEl =
        document.querySelector('#df-e264120c-1feb-4ffd-b466-d6506285bec4 button.colab-df-convert');
      buttonEl.style.display =
        google.colab.kernel.accessAllowed ? 'block' : 'none';

      async function convertToInteractive(key) {
        const element = document.querySelector('#df-e264120c-1feb-4ffd-b466-d6506285bec4');
        const dataTable =
          await google.colab.kernel.invokeFunction('convertToInteractive',
                                                    [key], {});
        if (!dataTable) return;

        const docLinkHtml = 'Like what you see? Visit the ' +
          '<a target="_blank" href=https://colab.research.google.com/notebooks/data_table.ipynb>data table notebook</a>'
          + ' to learn more about interactive tables.';
        element.innerHTML = '';
        dataTable['output_type'] = 'display_data';
        await google.colab.output.renderOutput(dataTable, element);
        const docLink = document.createElement('div');
        docLink.innerHTML = docLinkHtml;
        element.appendChild(docLink);
      }
    </script>
  </div>


    <div id="df-5d475596-d192-4ec4-b96a-2dde00373b69">
      <button class="colab-df-quickchart" onclick="quickchart('df-5d475596-d192-4ec4-b96a-2dde00373b69')"
                title="Suggest charts"
                style="display:none;">

<svg xmlns="http://www.w3.org/2000/svg" height="24px"viewBox="0 0 24 24"
     width="24px">
    <g>
        <path d="M19 3H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zM9 17H7v-7h2v7zm4 0h-2V7h2v10zm4 0h-2v-4h2v4z"/>
    </g>
</svg>
      </button>

<style>
  .colab-df-quickchart {
      --bg-color: #E8F0FE;
      --fill-color: #1967D2;
      --hover-bg-color: #E2EBFA;
      --hover-fill-color: #174EA6;
      --disabled-fill-color: #AAA;
      --disabled-bg-color: #DDD;
  }

  [theme=dark] .colab-df-quickchart {
      --bg-color: #3B4455;
      --fill-color: #D2E3FC;
      --hover-bg-color: #434B5C;
      --hover-fill-color: #FFFFFF;
      --disabled-bg-color: #3B4455;
      --disabled-fill-color: #666;
  }

  .colab-df-quickchart {
    background-color: var(--bg-color);
    border: none;
    border-radius: 50%;
    cursor: pointer;
    display: none;
    fill: var(--fill-color);
    height: 32px;
    padding: 0;
    width: 32px;
  }

  .colab-df-quickchart:hover {
    background-color: var(--hover-bg-color);
    box-shadow: 0 1px 2px rgba(60, 64, 67, 0.3), 0 1px 3px 1px rgba(60, 64, 67, 0.15);
    fill: var(--button-hover-fill-color);
  }

  .colab-df-quickchart-complete:disabled,
  .colab-df-quickchart-complete:disabled:hover {
    background-color: var(--disabled-bg-color);
    fill: var(--disabled-fill-color);
    box-shadow: none;
  }

  .colab-df-spinner {
    border: 2px solid var(--fill-color);
    border-color: transparent;
    border-bottom-color: var(--fill-color);
    animation:
      spin 1s steps(1) infinite;
  }

  @keyframes spin {
    0% {
      border-color: transparent;
      border-bottom-color: var(--fill-color);
      border-left-color: var(--fill-color);
    }
    20% {
      border-color: transparent;
      border-left-color: var(--fill-color);
      border-top-color: var(--fill-color);
    }
    30% {
      border-color: transparent;
      border-left-color: var(--fill-color);
      border-top-color: var(--fill-color);
      border-right-color: var(--fill-color);
    }
    40% {
      border-color: transparent;
      border-right-color: var(--fill-color);
      border-top-color: var(--fill-color);
    }
    60% {
      border-color: transparent;
      border-right-color: var(--fill-color);
    }
    80% {
      border-color: transparent;
      border-right-color: var(--fill-color);
      border-bottom-color: var(--fill-color);
    }
    90% {
      border-color: transparent;
      border-bottom-color: var(--fill-color);
    }
  }
</style>

      <script>
        async function quickchart(key) {
          const quickchartButtonEl =
            document.querySelector('#' + key + ' button');
          quickchartButtonEl.disabled = true;  // To prevent multiple clicks.
          quickchartButtonEl.classList.add('colab-df-spinner');
          try {
            const charts = await google.colab.kernel.invokeFunction(
                'suggestCharts', [key], {});
          } catch (error) {
            console.error('Error during call to suggestCharts:', error);
          }
          quickchartButtonEl.classList.remove('colab-df-spinner');
          quickchartButtonEl.classList.add('colab-df-quickchart-complete');
        }
        (() => {
          let quickchartButtonEl =
            document.querySelector('#df-5d475596-d192-4ec4-b96a-2dde00373b69 button');
          quickchartButtonEl.style.display =
            google.colab.kernel.accessAllowed ? 'block' : 'none';
        })();
      </script>
    </div>

  <div id="id_cbbacb3b-d4f2-4cd1-983b-f0fea76a166b">
    <style>
      .colab-df-generate {
        background-color: #E8F0FE;
        border: none;
        border-radius: 50%;
        cursor: pointer;
        display: none;
        fill: #1967D2;
        height: 32px;
        padding: 0 0 0 0;
        width: 32px;
      }

      .colab-df-generate:hover {
        background-color: #E2EBFA;
        box-shadow: 0px 1px 2px rgba(60, 64, 67, 0.3), 0px 1px 3px 1px rgba(60, 64, 67, 0.15);
        fill: #174EA6;
      }

      [theme=dark] .colab-df-generate {
        background-color: #3B4455;
        fill: #D2E3FC;
      }

      [theme=dark] .colab-df-generate:hover {
        background-color: #434B5C;
        box-shadow: 0px 1px 3px 1px rgba(0, 0, 0, 0.15);
        filter: drop-shadow(0px 1px 2px rgba(0, 0, 0, 0.3));
        fill: #FFFFFF;
      }
    </style>
    <button class="colab-df-generate" onclick="generateWithVariable('df')"
            title="Generate code using this dataframe."
            style="display:none;">

  <svg xmlns="http://www.w3.org/2000/svg" height="24px"viewBox="0 0 24 24"
       width="24px">
    <path d="M7,19H8.4L18.45,9,17,7.55,7,17.6ZM5,21V16.75L18.45,3.32a2,2,0,0,1,2.83,0l1.4,1.43a1.91,1.91,0,0,1,.58,1.4,1.91,1.91,0,0,1-.58,1.4L9.25,21ZM18.45,9,17,7.55Zm-12,3A5.31,5.31,0,0,0,4.9,8.1,5.31,5.31,0,0,0,1,6.5,5.31,5.31,0,0,0,4.9,4.9,5.31,5.31,0,0,0,6.5,1,5.31,5.31,0,0,0,8.1,4.9,5.31,5.31,0,0,0,12,6.5,5.46,5.46,0,0,0,6.5,12Z"/>
  </svg>
    </button>
    <script>
      (() => {
      const buttonEl =
        document.querySelector('#id_cbbacb3b-d4f2-4cd1-983b-f0fea76a166b button.colab-df-generate');
      buttonEl.style.display =
        google.colab.kernel.accessAllowed ? 'block' : 'none';

      buttonEl.onclick = () => {
        google.colab.notebook.generateWithVariable('df');
      }
      })();
    </script>
  </div>

    </div>
  </div>


<h3><span id="toc12">4. NumPy配列から作成する</span></h3>
<p>すでに NumPy配列 としてデータを持っている場合は、そのまま pd.DataFrame() に渡すこともできます。</p>

<pre class="line-numbers"><code class="language-python">
# Numpyのインポート
# NumpyをPythonコード内で使うために、まずインポートします。一般的に、npという別名でインポートします。
import numpy as np

# NumPyは高速な数値計算を行うためのライブラリですが、
# 初心者の方は現時点でその詳細な使い方を深く気にする必要はありません。
# Pandas DataFrameを作成する際などに利用されることがある、という認識でまずは十分です。
# 同じ型の要素を持つ多次元配列を効率的に扱うのに役立ちます。

data = np.array([[1, &#x27;Alice&#x27;, 24],
                 [2, &#x27;Bob&#x27;, 27],
                 [3, &#x27;Charlie&#x27;, 22],
                 [4, &#x27;David&#x27;, 32],
                 [5, &#x27;Eve&#x27;, 29]
                 ])
df = pd.DataFrame(data, columns=[&#x27;ID&#x27;, &#x27;Name&#x27;, &#x27;Age&#x27;])
display(df)
</code></pre>


  <div id="df-e6f3189a-2b84-4ea9-a12e-860504f68af5" class="colab-df-container">
    <div>
<style scoped>
    .dataframe tbody tr th:only-of-type {
        vertical-align: middle;
    }

    .dataframe tbody tr th {
        vertical-align: top;
    }

    .dataframe thead th {
        text-align: right;
    }
</style>
<table class="wp-block-table">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th>ID</th>
      <th>Name</th>
      <th>Age</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>0</th>
      <td>1</td>
      <td>Alice</td>
      <td>24</td>
    </tr>
    <tr>
      <th>1</th>
      <td>2</td>
      <td>Bob</td>
      <td>27</td>
    </tr>
    <tr>
      <th>2</th>
      <td>3</td>
      <td>Charlie</td>
      <td>22</td>
    </tr>
    <tr>
      <th>3</th>
      <td>4</td>
      <td>David</td>
      <td>32</td>
    </tr>
    <tr>
      <th>4</th>
      <td>5</td>
      <td>Eve</td>
      <td>29</td>
    </tr>
  </tbody>
</table>
</div>
    <div class="colab-df-buttons">

  <div class="colab-df-container">
    <button class="colab-df-convert" onclick="convertToInteractive('df-e6f3189a-2b84-4ea9-a12e-860504f68af5')"
            title="Convert this dataframe to an interactive table."
            style="display:none;">

  <svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 -960 960 960">
    <path d="M120-120v-720h720v720H120Zm60-500h600v-160H180v160Zm220 220h160v-160H400v160Zm0 220h160v-160H400v160ZM180-400h160v-160H180v160Zm440 0h160v-160H620v160ZM180-180h160v-160H180v160Zm440 0h160v-160H620v160Z"/>
  </svg>
    </button>

  <style>
    .colab-df-container {
      display:flex;
      gap: 12px;
    }

    .colab-df-convert {
      background-color: #E8F0FE;
      border: none;
      border-radius: 50%;
      cursor: pointer;
      display: none;
      fill: #1967D2;
      height: 32px;
      padding: 0 0 0 0;
      width: 32px;
    }

    .colab-df-convert:hover {
      background-color: #E2EBFA;
      box-shadow: 0px 1px 2px rgba(60, 64, 67, 0.3), 0px 1px 3px 1px rgba(60, 64, 67, 0.15);
      fill: #174EA6;
    }

    .colab-df-buttons div {
      margin-bottom: 4px;
    }

    [theme=dark] .colab-df-convert {
      background-color: #3B4455;
      fill: #D2E3FC;
    }

    [theme=dark] .colab-df-convert:hover {
      background-color: #434B5C;
      box-shadow: 0px 1px 3px 1px rgba(0, 0, 0, 0.15);
      filter: drop-shadow(0px 1px 2px rgba(0, 0, 0, 0.3));
      fill: #FFFFFF;
    }
  </style>

    <script>
      const buttonEl =
        document.querySelector('#df-e6f3189a-2b84-4ea9-a12e-860504f68af5 button.colab-df-convert');
      buttonEl.style.display =
        google.colab.kernel.accessAllowed ? 'block' : 'none';

      async function convertToInteractive(key) {
        const element = document.querySelector('#df-e6f3189a-2b84-4ea9-a12e-860504f68af5');
        const dataTable =
          await google.colab.kernel.invokeFunction('convertToInteractive',
                                                    [key], {});
        if (!dataTable) return;

        const docLinkHtml = 'Like what you see? Visit the ' +
          '<a target="_blank" href=https://colab.research.google.com/notebooks/data_table.ipynb>data table notebook</a>'
          + ' to learn more about interactive tables.';
        element.innerHTML = '';
        dataTable['output_type'] = 'display_data';
        await google.colab.output.renderOutput(dataTable, element);
        const docLink = document.createElement('div');
        docLink.innerHTML = docLinkHtml;
        element.appendChild(docLink);
      }
    </script>
  </div>


    <div id="df-017ae443-41f0-4d5c-81eb-d629f3c8784f">
      <button class="colab-df-quickchart" onclick="quickchart('df-017ae443-41f0-4d5c-81eb-d629f3c8784f')"
                title="Suggest charts"
                style="display:none;">

<svg xmlns="http://www.w3.org/2000/svg" height="24px"viewBox="0 0 24 24"
     width="24px">
    <g>
        <path d="M19 3H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zM9 17H7v-7h2v7zm4 0h-2V7h2v10zm4 0h-2v-4h2v4z"/>
    </g>
</svg>
      </button>

<style>
  .colab-df-quickchart {
      --bg-color: #E8F0FE;
      --fill-color: #1967D2;
      --hover-bg-color: #E2EBFA;
      --hover-fill-color: #174EA6;
      --disabled-fill-color: #AAA;
      --disabled-bg-color: #DDD;
  }

  [theme=dark] .colab-df-quickchart {
      --bg-color: #3B4455;
      --fill-color: #D2E3FC;
      --hover-bg-color: #434B5C;
      --hover-fill-color: #FFFFFF;
      --disabled-bg-color: #3B4455;
      --disabled-fill-color: #666;
  }

  .colab-df-quickchart {
    background-color: var(--bg-color);
    border: none;
    border-radius: 50%;
    cursor: pointer;
    display: none;
    fill: var(--fill-color);
    height: 32px;
    padding: 0;
    width: 32px;
  }

  .colab-df-quickchart:hover {
    background-color: var(--hover-bg-color);
    box-shadow: 0 1px 2px rgba(60, 64, 67, 0.3), 0 1px 3px 1px rgba(60, 64, 67, 0.15);
    fill: var(--button-hover-fill-color);
  }

  .colab-df-quickchart-complete:disabled,
  .colab-df-quickchart-complete:disabled:hover {
    background-color: var(--disabled-bg-color);
    fill: var(--disabled-fill-color);
    box-shadow: none;
  }

  .colab-df-spinner {
    border: 2px solid var(--fill-color);
    border-color: transparent;
    border-bottom-color: var(--fill-color);
    animation:
      spin 1s steps(1) infinite;
  }

  @keyframes spin {
    0% {
      border-color: transparent;
      border-bottom-color: var(--fill-color);
      border-left-color: var(--fill-color);
    }
    20% {
      border-color: transparent;
      border-left-color: var(--fill-color);
      border-top-color: var(--fill-color);
    }
    30% {
      border-color: transparent;
      border-left-color: var(--fill-color);
      border-top-color: var(--fill-color);
      border-right-color: var(--fill-color);
    }
    40% {
      border-color: transparent;
      border-right-color: var(--fill-color);
      border-top-color: var(--fill-color);
    }
    60% {
      border-color: transparent;
      border-right-color: var(--fill-color);
    }
    80% {
      border-color: transparent;
      border-right-color: var(--fill-color);
      border-bottom-color: var(--fill-color);
    }
    90% {
      border-color: transparent;
      border-bottom-color: var(--fill-color);
    }
  }
</style>

      <script>
        async function quickchart(key) {
          const quickchartButtonEl =
            document.querySelector('#' + key + ' button');
          quickchartButtonEl.disabled = true;  // To prevent multiple clicks.
          quickchartButtonEl.classList.add('colab-df-spinner');
          try {
            const charts = await google.colab.kernel.invokeFunction(
                'suggestCharts', [key], {});
          } catch (error) {
            console.error('Error during call to suggestCharts:', error);
          }
          quickchartButtonEl.classList.remove('colab-df-spinner');
          quickchartButtonEl.classList.add('colab-df-quickchart-complete');
        }
        (() => {
          let quickchartButtonEl =
            document.querySelector('#df-017ae443-41f0-4d5c-81eb-d629f3c8784f button');
          quickchartButtonEl.style.display =
            google.colab.kernel.accessAllowed ? 'block' : 'none';
        })();
      </script>
    </div>

  <div id="id_b439298c-102a-4f4b-a30e-a9d841a00a2e">
    <style>
      .colab-df-generate {
        background-color: #E8F0FE;
        border: none;
        border-radius: 50%;
        cursor: pointer;
        display: none;
        fill: #1967D2;
        height: 32px;
        padding: 0 0 0 0;
        width: 32px;
      }

      .colab-df-generate:hover {
        background-color: #E2EBFA;
        box-shadow: 0px 1px 2px rgba(60, 64, 67, 0.3), 0px 1px 3px 1px rgba(60, 64, 67, 0.15);
        fill: #174EA6;
      }

      [theme=dark] .colab-df-generate {
        background-color: #3B4455;
        fill: #D2E3FC;
      }

      [theme=dark] .colab-df-generate:hover {
        background-color: #434B5C;
        box-shadow: 0px 1px 3px 1px rgba(0, 0, 0, 0.15);
        filter: drop-shadow(0px 1px 2px rgba(0, 0, 0, 0.3));
        fill: #FFFFFF;
      }
    </style>
    <button class="colab-df-generate" onclick="generateWithVariable('df')"
            title="Generate code using this dataframe."
            style="display:none;">

  <svg xmlns="http://www.w3.org/2000/svg" height="24px"viewBox="0 0 24 24"
       width="24px">
    <path d="M7,19H8.4L18.45,9,17,7.55,7,17.6ZM5,21V16.75L18.45,3.32a2,2,0,0,1,2.83,0l1.4,1.43a1.91,1.91,0,0,1,.58,1.4,1.91,1.91,0,0,1-.58,1.4L9.25,21ZM18.45,9,17,7.55Zm-12,3A5.31,5.31,0,0,0,4.9,8.1,5.31,5.31,0,0,0,1,6.5,5.31,5.31,0,0,0,4.9,4.9,5.31,5.31,0,0,0,6.5,1,5.31,5.31,0,0,0,8.1,4.9,5.31,5.31,0,0,0,12,6.5,5.46,5.46,0,0,0,6.5,12Z"/>
  </svg>
    </button>
    <script>
      (() => {
      const buttonEl =
        document.querySelector('#id_b439298c-102a-4f4b-a30e-a9d841a00a2e button.colab-df-generate');
      buttonEl.style.display =
        google.colab.kernel.accessAllowed ? 'block' : 'none';

      buttonEl.onclick = () => {
        google.colab.notebook.generateWithVariable('df');
      }
      })();
    </script>
  </div>

    </div>
  </div>


<h3><span id="toc13">5. インデックスを指定して作成・変更する</span></h3>
<p>インデックス（index） は各行のラベルで、DataFrame の「行番号」を人間が使いやすい形にしたものです。デフォルトでは 0, 1, 2, &#8230; の連番ですが、ID や日付など意味のある値に変えると、後の抽出や結合が分かりやすくなります。</p>

<pre class="line-numbers"><code class="language-python">
data_dict_for_index = {&#x27;ID&#x27;: [1, 2, 3, 4, 5],
                       &#x27;Name&#x27;: [&#x27;Alice&#x27;, &#x27;Bob&#x27;, &#x27;Charlie&#x27;, &#x27;David&#x27;, &#x27;Eve&#x27;],
                       &#x27;Age&#x27;: [24, 27, 22, 32, 29]}
df_index_example = pd.DataFrame(data_dict_for_index) # 元のdfを上書きしないように変数名を変更

display(&#x27;インデックス設定前のDataFrame:&#x27;, df_index_example)

# &#x27;ID&#x27;列をインデックスに設定
df_with_index = df_index_example.set_index(&#x27;ID&#x27;)

display(&#x27;ID列をインデックスに設定したDataFrame:&#x27;, df_with_index)

</code></pre>

<p>&#8216;インデックス設定前のDataFrame:&#8217;</p>
  <div id="df-a4c6cf14-47e7-4e64-a789-2b2af744f913" class="colab-df-container">
    <div>
<style scoped>
    .dataframe tbody tr th:only-of-type {
        vertical-align: middle;
    }

    .dataframe tbody tr th {
        vertical-align: top;
    }

    .dataframe thead th {
        text-align: right;
    }
</style>
<table class="wp-block-table">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th>ID</th>
      <th>Name</th>
      <th>Age</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>0</th>
      <td>1</td>
      <td>Alice</td>
      <td>24</td>
    </tr>
    <tr>
      <th>1</th>
      <td>2</td>
      <td>Bob</td>
      <td>27</td>
    </tr>
    <tr>
      <th>2</th>
      <td>3</td>
      <td>Charlie</td>
      <td>22</td>
    </tr>
    <tr>
      <th>3</th>
      <td>4</td>
      <td>David</td>
      <td>32</td>
    </tr>
    <tr>
      <th>4</th>
      <td>5</td>
      <td>Eve</td>
      <td>29</td>
    </tr>
  </tbody>
</table>
</div>
    <div class="colab-df-buttons">

  <div class="colab-df-container">
    <button class="colab-df-convert" onclick="convertToInteractive('df-a4c6cf14-47e7-4e64-a789-2b2af744f913')"
            title="Convert this dataframe to an interactive table."
            style="display:none;">

  <svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 -960 960 960">
    <path d="M120-120v-720h720v720H120Zm60-500h600v-160H180v160Zm220 220h160v-160H400v160Zm0 220h160v-160H400v160ZM180-400h160v-160H180v160Zm440 0h160v-160H620v160ZM180-180h160v-160H180v160Zm440 0h160v-160H620v160Z"/>
  </svg>
    </button>

  <style>
    .colab-df-container {
      display:flex;
      gap: 12px;
    }

    .colab-df-convert {
      background-color: #E8F0FE;
      border: none;
      border-radius: 50%;
      cursor: pointer;
      display: none;
      fill: #1967D2;
      height: 32px;
      padding: 0 0 0 0;
      width: 32px;
    }

    .colab-df-convert:hover {
      background-color: #E2EBFA;
      box-shadow: 0px 1px 2px rgba(60, 64, 67, 0.3), 0px 1px 3px 1px rgba(60, 64, 67, 0.15);
      fill: #174EA6;
    }

    .colab-df-buttons div {
      margin-bottom: 4px;
    }

    [theme=dark] .colab-df-convert {
      background-color: #3B4455;
      fill: #D2E3FC;
    }

    [theme=dark] .colab-df-convert:hover {
      background-color: #434B5C;
      box-shadow: 0px 1px 3px 1px rgba(0, 0, 0, 0.15);
      filter: drop-shadow(0px 1px 2px rgba(0, 0, 0, 0.3));
      fill: #FFFFFF;
    }
  </style>

    <script>
      const buttonEl =
        document.querySelector('#df-a4c6cf14-47e7-4e64-a789-2b2af744f913 button.colab-df-convert');
      buttonEl.style.display =
        google.colab.kernel.accessAllowed ? 'block' : 'none';

      async function convertToInteractive(key) {
        const element = document.querySelector('#df-a4c6cf14-47e7-4e64-a789-2b2af744f913');
        const dataTable =
          await google.colab.kernel.invokeFunction('convertToInteractive',
                                                    [key], {});
        if (!dataTable) return;

        const docLinkHtml = 'Like what you see? Visit the ' +
          '<a target="_blank" href=https://colab.research.google.com/notebooks/data_table.ipynb>data table notebook</a>'
          + ' to learn more about interactive tables.';
        element.innerHTML = '';
        dataTable['output_type'] = 'display_data';
        await google.colab.output.renderOutput(dataTable, element);
        const docLink = document.createElement('div');
        docLink.innerHTML = docLinkHtml;
        element.appendChild(docLink);
      }
    </script>
  </div>


    <div id="df-929d0a11-80eb-4da5-8342-1b86ba987f2f">
      <button class="colab-df-quickchart" onclick="quickchart('df-929d0a11-80eb-4da5-8342-1b86ba987f2f')"
                title="Suggest charts"
                style="display:none;">

<svg xmlns="http://www.w3.org/2000/svg" height="24px"viewBox="0 0 24 24"
     width="24px">
    <g>
        <path d="M19 3H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zM9 17H7v-7h2v7zm4 0h-2V7h2v10zm4 0h-2v-4h2v4z"/>
    </g>
</svg>
      </button>

<style>
  .colab-df-quickchart {
      --bg-color: #E8F0FE;
      --fill-color: #1967D2;
      --hover-bg-color: #E2EBFA;
      --hover-fill-color: #174EA6;
      --disabled-fill-color: #AAA;
      --disabled-bg-color: #DDD;
  }

  [theme=dark] .colab-df-quickchart {
      --bg-color: #3B4455;
      --fill-color: #D2E3FC;
      --hover-bg-color: #434B5C;
      --hover-fill-color: #FFFFFF;
      --disabled-bg-color: #3B4455;
      --disabled-fill-color: #666;
  }

  .colab-df-quickchart {
    background-color: var(--bg-color);
    border: none;
    border-radius: 50%;
    cursor: pointer;
    display: none;
    fill: var(--fill-color);
    height: 32px;
    padding: 0;
    width: 32px;
  }

  .colab-df-quickchart:hover {
    background-color: var(--hover-bg-color);
    box-shadow: 0 1px 2px rgba(60, 64, 67, 0.3), 0 1px 3px 1px rgba(60, 64, 67, 0.15);
    fill: var(--button-hover-fill-color);
  }

  .colab-df-quickchart-complete:disabled,
  .colab-df-quickchart-complete:disabled:hover {
    background-color: var(--disabled-bg-color);
    fill: var(--disabled-fill-color);
    box-shadow: none;
  }

  .colab-df-spinner {
    border: 2px solid var(--fill-color);
    border-color: transparent;
    border-bottom-color: var(--fill-color);
    animation:
      spin 1s steps(1) infinite;
  }

  @keyframes spin {
    0% {
      border-color: transparent;
      border-bottom-color: var(--fill-color);
      border-left-color: var(--fill-color);
    }
    20% {
      border-color: transparent;
      border-left-color: var(--fill-color);
      border-top-color: var(--fill-color);
    }
    30% {
      border-color: transparent;
      border-left-color: var(--fill-color);
      border-top-color: var(--fill-color);
      border-right-color: var(--fill-color);
    }
    40% {
      border-color: transparent;
      border-right-color: var(--fill-color);
      border-top-color: var(--fill-color);
    }
    60% {
      border-color: transparent;
      border-right-color: var(--fill-color);
    }
    80% {
      border-color: transparent;
      border-right-color: var(--fill-color);
      border-bottom-color: var(--fill-color);
    }
    90% {
      border-color: transparent;
      border-bottom-color: var(--fill-color);
    }
  }
</style>

      <script>
        async function quickchart(key) {
          const quickchartButtonEl =
            document.querySelector('#' + key + ' button');
          quickchartButtonEl.disabled = true;  // To prevent multiple clicks.
          quickchartButtonEl.classList.add('colab-df-spinner');
          try {
            const charts = await google.colab.kernel.invokeFunction(
                'suggestCharts', [key], {});
          } catch (error) {
            console.error('Error during call to suggestCharts:', error);
          }
          quickchartButtonEl.classList.remove('colab-df-spinner');
          quickchartButtonEl.classList.add('colab-df-quickchart-complete');
        }
        (() => {
          let quickchartButtonEl =
            document.querySelector('#df-929d0a11-80eb-4da5-8342-1b86ba987f2f button');
          quickchartButtonEl.style.display =
            google.colab.kernel.accessAllowed ? 'block' : 'none';
        })();
      </script>
    </div>

  <div id="id_df2c3cc5-1d43-4ab3-b202-e2629a27a3e6">
    <style>
      .colab-df-generate {
        background-color: #E8F0FE;
        border: none;
        border-radius: 50%;
        cursor: pointer;
        display: none;
        fill: #1967D2;
        height: 32px;
        padding: 0 0 0 0;
        width: 32px;
      }

      .colab-df-generate:hover {
        background-color: #E2EBFA;
        box-shadow: 0px 1px 2px rgba(60, 64, 67, 0.3), 0px 1px 3px 1px rgba(60, 64, 67, 0.15);
        fill: #174EA6;
      }

      [theme=dark] .colab-df-generate {
        background-color: #3B4455;
        fill: #D2E3FC;
      }

      [theme=dark] .colab-df-generate:hover {
        background-color: #434B5C;
        box-shadow: 0px 1px 3px 1px rgba(0, 0, 0, 0.15);
        filter: drop-shadow(0px 1px 2px rgba(0, 0, 0, 0.3));
        fill: #FFFFFF;
      }
    </style>
    <button class="colab-df-generate" onclick="generateWithVariable('df_index_example')"
            title="Generate code using this dataframe."
            style="display:none;">

  <svg xmlns="http://www.w3.org/2000/svg" height="24px"viewBox="0 0 24 24"
       width="24px">
    <path d="M7,19H8.4L18.45,9,17,7.55,7,17.6ZM5,21V16.75L18.45,3.32a2,2,0,0,1,2.83,0l1.4,1.43a1.91,1.91,0,0,1,.58,1.4,1.91,1.91,0,0,1-.58,1.4L9.25,21ZM18.45,9,17,7.55Zm-12,3A5.31,5.31,0,0,0,4.9,8.1,5.31,5.31,0,0,0,1,6.5,5.31,5.31,0,0,0,4.9,4.9,5.31,5.31,0,0,0,6.5,1,5.31,5.31,0,0,0,8.1,4.9,5.31,5.31,0,0,0,12,6.5,5.46,5.46,0,0,0,6.5,12Z"/>
  </svg>
    </button>
    <script>
      (() => {
      const buttonEl =
        document.querySelector('#id_df2c3cc5-1d43-4ab3-b202-e2629a27a3e6 button.colab-df-generate');
      buttonEl.style.display =
        google.colab.kernel.accessAllowed ? 'block' : 'none';

      buttonEl.onclick = () => {
        google.colab.notebook.generateWithVariable('df_index_example');
      }
      })();
    </script>
  </div>

    </div>
  </div>



  <div id="df-786e38e1-54aa-49a4-a13d-5a9566a8d702" class="colab-df-container">
    <div>
<style scoped>
    .dataframe tbody tr th:only-of-type {
        vertical-align: middle;
    }

    .dataframe tbody tr th {
        vertical-align: top;
    }

    .dataframe thead th {
        text-align: right;
    }
</style>

<p>&#8216;ID列をインデックスに設定したDataFrame:&#8217; </p>
<table class="wp-block-table">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th>Name</th>
      <th>Age</th>
    </tr>
    <tr>
      <th>ID</th>
      <th></th>
      <th></th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>1</th>
      <td>Alice</td>
      <td>24</td>
    </tr>
    <tr>
      <th>2</th>
      <td>Bob</td>
      <td>27</td>
    </tr>
    <tr>
      <th>3</th>
      <td>Charlie</td>
      <td>22</td>
    </tr>
    <tr>
      <th>4</th>
      <td>David</td>
      <td>32</td>
    </tr>
    <tr>
      <th>5</th>
      <td>Eve</td>
      <td>29</td>
    </tr>
  </tbody>
</table>
</div>
    <div class="colab-df-buttons">

  <div class="colab-df-container">
    <button class="colab-df-convert" onclick="convertToInteractive('df-786e38e1-54aa-49a4-a13d-5a9566a8d702')"
            title="Convert this dataframe to an interactive table."
            style="display:none;">

  <svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 -960 960 960">
    <path d="M120-120v-720h720v720H120Zm60-500h600v-160H180v160Zm220 220h160v-160H400v160Zm0 220h160v-160H400v160ZM180-400h160v-160H180v160Zm440 0h160v-160H620v160ZM180-180h160v-160H180v160Zm440 0h160v-160H620v160Z"/>
  </svg>
    </button>

  <style>
    .colab-df-container {
      display:flex;
      gap: 12px;
    }

    .colab-df-convert {
      background-color: #E8F0FE;
      border: none;
      border-radius: 50%;
      cursor: pointer;
      display: none;
      fill: #1967D2;
      height: 32px;
      padding: 0 0 0 0;
      width: 32px;
    }

    .colab-df-convert:hover {
      background-color: #E2EBFA;
      box-shadow: 0px 1px 2px rgba(60, 64, 67, 0.3), 0px 1px 3px 1px rgba(60, 64, 67, 0.15);
      fill: #174EA6;
    }

    .colab-df-buttons div {
      margin-bottom: 4px;
    }

    [theme=dark] .colab-df-convert {
      background-color: #3B4455;
      fill: #D2E3FC;
    }

    [theme=dark] .colab-df-convert:hover {
      background-color: #434B5C;
      box-shadow: 0px 1px 3px 1px rgba(0, 0, 0, 0.15);
      filter: drop-shadow(0px 1px 2px rgba(0, 0, 0, 0.3));
      fill: #FFFFFF;
    }
  </style>

    <script>
      const buttonEl =
        document.querySelector('#df-786e38e1-54aa-49a4-a13d-5a9566a8d702 button.colab-df-convert');
      buttonEl.style.display =
        google.colab.kernel.accessAllowed ? 'block' : 'none';

      async function convertToInteractive(key) {
        const element = document.querySelector('#df-786e38e1-54aa-49a4-a13d-5a9566a8d702');
        const dataTable =
          await google.colab.kernel.invokeFunction('convertToInteractive',
                                                    [key], {});
        if (!dataTable) return;

        const docLinkHtml = 'Like what you see? Visit the ' +
          '<a target="_blank" href=https://colab.research.google.com/notebooks/data_table.ipynb>data table notebook</a>'
          + ' to learn more about interactive tables.';
        element.innerHTML = '';
        dataTable['output_type'] = 'display_data';
        await google.colab.output.renderOutput(dataTable, element);
        const docLink = document.createElement('div');
        docLink.innerHTML = docLinkHtml;
        element.appendChild(docLink);
      }
    </script>
  </div>


    <div id="df-0cf322e6-50b6-4785-991f-da4b3db39ced">
      <button class="colab-df-quickchart" onclick="quickchart('df-0cf322e6-50b6-4785-991f-da4b3db39ced')"
                title="Suggest charts"
                style="display:none;">

<svg xmlns="http://www.w3.org/2000/svg" height="24px"viewBox="0 0 24 24"
     width="24px">
    <g>
        <path d="M19 3H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zM9 17H7v-7h2v7zm4 0h-2V7h2v10zm4 0h-2v-4h2v4z"/>
    </g>
</svg>
      </button>

<style>
  .colab-df-quickchart {
      --bg-color: #E8F0FE;
      --fill-color: #1967D2;
      --hover-bg-color: #E2EBFA;
      --hover-fill-color: #174EA6;
      --disabled-fill-color: #AAA;
      --disabled-bg-color: #DDD;
  }

  [theme=dark] .colab-df-quickchart {
      --bg-color: #3B4455;
      --fill-color: #D2E3FC;
      --hover-bg-color: #434B5C;
      --hover-fill-color: #FFFFFF;
      --disabled-bg-color: #3B4455;
      --disabled-fill-color: #666;
  }

  .colab-df-quickchart {
    background-color: var(--bg-color);
    border: none;
    border-radius: 50%;
    cursor: pointer;
    display: none;
    fill: var(--fill-color);
    height: 32px;
    padding: 0;
    width: 32px;
  }

  .colab-df-quickchart:hover {
    background-color: var(--hover-bg-color);
    box-shadow: 0 1px 2px rgba(60, 64, 67, 0.3), 0 1px 3px 1px rgba(60, 64, 67, 0.15);
    fill: var(--button-hover-fill-color);
  }

  .colab-df-quickchart-complete:disabled,
  .colab-df-quickchart-complete:disabled:hover {
    background-color: var(--disabled-bg-color);
    fill: var(--disabled-fill-color);
    box-shadow: none;
  }

  .colab-df-spinner {
    border: 2px solid var(--fill-color);
    border-color: transparent;
    border-bottom-color: var(--fill-color);
    animation:
      spin 1s steps(1) infinite;
  }

  @keyframes spin {
    0% {
      border-color: transparent;
      border-bottom-color: var(--fill-color);
      border-left-color: var(--fill-color);
    }
    20% {
      border-color: transparent;
      border-left-color: var(--fill-color);
      border-top-color: var(--fill-color);
    }
    30% {
      border-color: transparent;
      border-left-color: var(--fill-color);
      border-top-color: var(--fill-color);
      border-right-color: var(--fill-color);
    }
    40% {
      border-color: transparent;
      border-right-color: var(--fill-color);
      border-top-color: var(--fill-color);
    }
    60% {
      border-color: transparent;
      border-right-color: var(--fill-color);
    }
    80% {
      border-color: transparent;
      border-right-color: var(--fill-color);
      border-bottom-color: var(--fill-color);
    }
    90% {
      border-color: transparent;
      border-bottom-color: var(--fill-color);
    }
  }
</style>

      <script>
        async function quickchart(key) {
          const quickchartButtonEl =
            document.querySelector('#' + key + ' button');
          quickchartButtonEl.disabled = true;  // To prevent multiple clicks.
          quickchartButtonEl.classList.add('colab-df-spinner');
          try {
            const charts = await google.colab.kernel.invokeFunction(
                'suggestCharts', [key], {});
          } catch (error) {
            console.error('Error during call to suggestCharts:', error);
          }
          quickchartButtonEl.classList.remove('colab-df-spinner');
          quickchartButtonEl.classList.add('colab-df-quickchart-complete');
        }
        (() => {
          let quickchartButtonEl =
            document.querySelector('#df-0cf322e6-50b6-4785-991f-da4b3db39ced button');
          quickchartButtonEl.style.display =
            google.colab.kernel.accessAllowed ? 'block' : 'none';
        })();
      </script>
    </div>

  <div id="id_b554cfb9-bc4c-4f34-ad18-5afcdd2d042b">
    <style>
      .colab-df-generate {
        background-color: #E8F0FE;
        border: none;
        border-radius: 50%;
        cursor: pointer;
        display: none;
        fill: #1967D2;
        height: 32px;
        padding: 0 0 0 0;
        width: 32px;
      }

      .colab-df-generate:hover {
        background-color: #E2EBFA;
        box-shadow: 0px 1px 2px rgba(60, 64, 67, 0.3), 0px 1px 3px 1px rgba(60, 64, 67, 0.15);
        fill: #174EA6;
      }

      [theme=dark] .colab-df-generate {
        background-color: #3B4455;
        fill: #D2E3FC;
      }

      [theme=dark] .colab-df-generate:hover {
        background-color: #434B5C;
        box-shadow: 0px 1px 3px 1px rgba(0, 0, 0, 0.15);
        filter: drop-shadow(0px 1px 2px rgba(0, 0, 0, 0.3));
        fill: #FFFFFF;
      }
    </style>
    <button class="colab-df-generate" onclick="generateWithVariable('df_with_index')"
            title="Generate code using this dataframe."
            style="display:none;">

  <svg xmlns="http://www.w3.org/2000/svg" height="24px"viewBox="0 0 24 24"
       width="24px">
    <path d="M7,19H8.4L18.45,9,17,7.55,7,17.6ZM5,21V16.75L18.45,3.32a2,2,0,0,1,2.83,0l1.4,1.43a1.91,1.91,0,0,1,.58,1.4,1.91,1.91,0,0,1-.58,1.4L9.25,21ZM18.45,9,17,7.55Zm-12,3A5.31,5.31,0,0,0,4.9,8.1,5.31,5.31,0,0,0,1,6.5,5.31,5.31,0,0,0,4.9,4.9,5.31,5.31,0,0,0,6.5,1,5.31,5.31,0,0,0,8.1,4.9,5.31,5.31,0,0,0,12,6.5,5.46,5.46,0,0,0,6.5,12Z"/>
  </svg>
    </button>
    <script>
      (() => {
      const buttonEl =
        document.querySelector('#id_b554cfb9-bc4c-4f34-ad18-5afcdd2d042b button.colab-df-generate');
      buttonEl.style.display =
        google.colab.kernel.accessAllowed ? 'block' : 'none';

      buttonEl.onclick = () => {
        google.colab.notebook.generateWithVariable('df_with_index');
      }
      })();
    </script>
  </div>

    </div>
  </div>



<p>既存の DataFrame に対してインデックスを変更したい場合は、 set_index() や reset_index() を使います。</p>

<h3><span id="toc14">6. CSVファイルなど外部ファイルから作成する</span></h3>
<p>実務では、手書きのリストや辞書から作成するよりも、CSV / Excel / データベースなどのファイルから直接 DataFrameを読み込む ケースが多くなります。</p>

<p>既存のdf_index_exampleを利用してdata.csvを作成し、読み込みの準備をします。</p>

<pre class="line-numbers"><code class="language-python">
# CSVファイルを作成
df_index_example.to_csv(&#x27;data.csv&#x27;, index=False)
</code></pre>

<pre class="line-numbers"><code class="language-python">
# CSVファイルの読み込み
df = pd.read_csv(&quot;data.csv&quot;)
display(df)
</code></pre>


  <div id="df-0a101551-6e27-436a-8644-bb7f294ce799" class="colab-df-container">
    <div>
<style scoped>
    .dataframe tbody tr th:only-of-type {
        vertical-align: middle;
    }

    .dataframe tbody tr th {
        vertical-align: top;
    }

    .dataframe thead th {
        text-align: right;
    }
</style>
<table class="wp-block-table">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th>ID</th>
      <th>Name</th>
      <th>Age</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>0</th>
      <td>1</td>
      <td>Alice</td>
      <td>24</td>
    </tr>
    <tr>
      <th>1</th>
      <td>2</td>
      <td>Bob</td>
      <td>27</td>
    </tr>
    <tr>
      <th>2</th>
      <td>3</td>
      <td>Charlie</td>
      <td>22</td>
    </tr>
    <tr>
      <th>3</th>
      <td>4</td>
      <td>David</td>
      <td>32</td>
    </tr>
    <tr>
      <th>4</th>
      <td>5</td>
      <td>Eve</td>
      <td>29</td>
    </tr>
  </tbody>
</table>
</div>
    <div class="colab-df-buttons">

  <div class="colab-df-container">
    <button class="colab-df-convert" onclick="convertToInteractive('df-0a101551-6e27-436a-8644-bb7f294ce799')"
            title="Convert this dataframe to an interactive table."
            style="display:none;">

  <svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 -960 960 960">
    <path d="M120-120v-720h720v720H120Zm60-500h600v-160H180v160Zm220 220h160v-160H400v160Zm0 220h160v-160H400v160ZM180-400h160v-160H180v160Zm440 0h160v-160H620v160ZM180-180h160v-160H180v160Zm440 0h160v-160H620v160Z"/>
  </svg>
    </button>

  <style>
    .colab-df-container {
      display:flex;
      gap: 12px;
    }

    .colab-df-convert {
      background-color: #E8F0FE;
      border: none;
      border-radius: 50%;
      cursor: pointer;
      display: none;
      fill: #1967D2;
      height: 32px;
      padding: 0 0 0 0;
      width: 32px;
    }

    .colab-df-convert:hover {
      background-color: #E2EBFA;
      box-shadow: 0px 1px 2px rgba(60, 64, 67, 0.3), 0px 1px 3px 1px rgba(60, 64, 67, 0.15);
      fill: #174EA6;
    }

    .colab-df-buttons div {
      margin-bottom: 4px;
    }

    [theme=dark] .colab-df-convert {
      background-color: #3B4455;
      fill: #D2E3FC;
    }

    [theme=dark] .colab-df-convert:hover {
      background-color: #434B5C;
      box-shadow: 0px 1px 3px 1px rgba(0, 0, 0, 0.15);
      filter: drop-shadow(0px 1px 2px rgba(0, 0, 0, 0.3));
      fill: #FFFFFF;
    }
  </style>

    <script>
      const buttonEl =
        document.querySelector('#df-0a101551-6e27-436a-8644-bb7f294ce799 button.colab-df-convert');
      buttonEl.style.display =
        google.colab.kernel.accessAllowed ? 'block' : 'none';

      async function convertToInteractive(key) {
        const element = document.querySelector('#df-0a101551-6e27-436a-8644-bb7f294ce799');
        const dataTable =
          await google.colab.kernel.invokeFunction('convertToInteractive',
                                                    [key], {});
        if (!dataTable) return;

        const docLinkHtml = 'Like what you see? Visit the ' +
          '<a target="_blank" href=https://colab.research.google.com/notebooks/data_table.ipynb>data table notebook</a>'
          + ' to learn more about interactive tables.';
        element.innerHTML = '';
        dataTable['output_type'] = 'display_data';
        await google.colab.output.renderOutput(dataTable, element);
        const docLink = document.createElement('div');
        docLink.innerHTML = docLinkHtml;
        element.appendChild(docLink);
      }
    </script>
  </div>


    <div id="df-eb9d7415-9b63-4bd1-bf3e-df75e0898f81">
      <button class="colab-df-quickchart" onclick="quickchart('df-eb9d7415-9b63-4bd1-bf3e-df75e0898f81')"
                title="Suggest charts"
                style="display:none;">

<svg xmlns="http://www.w3.org/2000/svg" height="24px"viewBox="0 0 24 24"
     width="24px">
    <g>
        <path d="M19 3H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zM9 17H7v-7h2v7zm4 0h-2V7h2v10zm4 0h-2v-4h2v4z"/>
    </g>
</svg>
      </button>

<style>
  .colab-df-quickchart {
      --bg-color: #E8F0FE;
      --fill-color: #1967D2;
      --hover-bg-color: #E2EBFA;
      --hover-fill-color: #174EA6;
      --disabled-fill-color: #AAA;
      --disabled-bg-color: #DDD;
  }

  [theme=dark] .colab-df-quickchart {
      --bg-color: #3B4455;
      --fill-color: #D2E3FC;
      --hover-bg-color: #434B5C;
      --hover-fill-color: #FFFFFF;
      --disabled-bg-color: #3B4455;
      --disabled-fill-color: #666;
  }

  .colab-df-quickchart {
    background-color: var(--bg-color);
    border: none;
    border-radius: 50%;
    cursor: pointer;
    display: none;
    fill: var(--fill-color);
    height: 32px;
    padding: 0;
    width: 32px;
  }

  .colab-df-quickchart:hover {
    background-color: var(--hover-bg-color);
    box-shadow: 0 1px 2px rgba(60, 64, 67, 0.3), 0 1px 3px 1px rgba(60, 64, 67, 0.15);
    fill: var(--button-hover-fill-color);
  }

  .colab-df-quickchart-complete:disabled,
  .colab-df-quickchart-complete:disabled:hover {
    background-color: var(--disabled-bg-color);
    fill: var(--disabled-fill-color);
    box-shadow: none;
  }

  .colab-df-spinner {
    border: 2px solid var(--fill-color);
    border-color: transparent;
    border-bottom-color: var(--fill-color);
    animation:
      spin 1s steps(1) infinite;
  }

  @keyframes spin {
    0% {
      border-color: transparent;
      border-bottom-color: var(--fill-color);
      border-left-color: var(--fill-color);
    }
    20% {
      border-color: transparent;
      border-left-color: var(--fill-color);
      border-top-color: var(--fill-color);
    }
    30% {
      border-color: transparent;
      border-left-color: var(--fill-color);
      border-top-color: var(--fill-color);
      border-right-color: var(--fill-color);
    }
    40% {
      border-color: transparent;
      border-right-color: var(--fill-color);
      border-top-color: var(--fill-color);
    }
    60% {
      border-color: transparent;
      border-right-color: var(--fill-color);
    }
    80% {
      border-color: transparent;
      border-right-color: var(--fill-color);
      border-bottom-color: var(--fill-color);
    }
    90% {
      border-color: transparent;
      border-bottom-color: var(--fill-color);
    }
  }
</style>

      <script>
        async function quickchart(key) {
          const quickchartButtonEl =
            document.querySelector('#' + key + ' button');
          quickchartButtonEl.disabled = true;  // To prevent multiple clicks.
          quickchartButtonEl.classList.add('colab-df-spinner');
          try {
            const charts = await google.colab.kernel.invokeFunction(
                'suggestCharts', [key], {});
          } catch (error) {
            console.error('Error during call to suggestCharts:', error);
          }
          quickchartButtonEl.classList.remove('colab-df-spinner');
          quickchartButtonEl.classList.add('colab-df-quickchart-complete');
        }
        (() => {
          let quickchartButtonEl =
            document.querySelector('#df-eb9d7415-9b63-4bd1-bf3e-df75e0898f81 button');
          quickchartButtonEl.style.display =
            google.colab.kernel.accessAllowed ? 'block' : 'none';
        })();
      </script>
    </div>

  <div id="id_dd327177-0c9a-4760-b2a4-9bd8fa11aba1">
    <style>
      .colab-df-generate {
        background-color: #E8F0FE;
        border: none;
        border-radius: 50%;
        cursor: pointer;
        display: none;
        fill: #1967D2;
        height: 32px;
        padding: 0 0 0 0;
        width: 32px;
      }

      .colab-df-generate:hover {
        background-color: #E2EBFA;
        box-shadow: 0px 1px 2px rgba(60, 64, 67, 0.3), 0px 1px 3px 1px rgba(60, 64, 67, 0.15);
        fill: #174EA6;
      }

      [theme=dark] .colab-df-generate {
        background-color: #3B4455;
        fill: #D2E3FC;
      }

      [theme=dark] .colab-df-generate:hover {
        background-color: #434B5C;
        box-shadow: 0px 1px 3px 1px rgba(0, 0, 0, 0.15);
        filter: drop-shadow(0px 1px 2px rgba(0, 0, 0, 0.3));
        fill: #FFFFFF;
      }
    </style>
    <button class="colab-df-generate" onclick="generateWithVariable('df')"
            title="Generate code using this dataframe."
            style="display:none;">

  <svg xmlns="http://www.w3.org/2000/svg" height="24px"viewBox="0 0 24 24"
       width="24px">
    <path d="M7,19H8.4L18.45,9,17,7.55,7,17.6ZM5,21V16.75L18.45,3.32a2,2,0,0,1,2.83,0l1.4,1.43a1.91,1.91,0,0,1,.58,1.4,1.91,1.91,0,0,1-.58,1.4L9.25,21ZM18.45,9,17,7.55Zm-12,3A5.31,5.31,0,0,0,4.9,8.1,5.31,5.31,0,0,0,1,6.5,5.31,5.31,0,0,0,4.9,4.9,5.31,5.31,0,0,0,6.5,1,5.31,5.31,0,0,0,8.1,4.9,5.31,5.31,0,0,0,12,6.5,5.46,5.46,0,0,0,6.5,12Z"/>
  </svg>
    </button>
    <script>
      (() => {
      const buttonEl =
        document.querySelector('#id_dd327177-0c9a-4760-b2a4-9bd8fa11aba1 button.colab-df-generate');
      buttonEl.style.display =
        google.colab.kernel.accessAllowed ? 'block' : 'none';

      buttonEl.onclick = () => {
        google.colab.notebook.generateWithVariable('df');
      }
      })();
    </script>
  </div>

    </div>
  </div>


<p>外部ファイルからの読み込みは DataFrame の代表的な利用シーンです。 詳しい使い方は、
<a class="prev-link" href="https://pythondatalab.com/google-colab-csv/">Google ColabでCSVを読み書きする方法 </a>
で詳しく解説しています。</p>

<h2><span id="toc15">Pandas DataFrame と Series の違いを徹底理解</span></h2>

<h3><span id="toc16">Seriesとは？：DataFrameの「1列」を表す1次元データ構造</span></h3>
<p>Series は、DataFrame の「1列」に相当する 1次元のデータ構造 です。</p>

  <figure>
    <img
      src="https://pythondatalab.com/wp-content/uploads/2025/05/pandas_difference_series_dataframe.png"
      alt="PandasのSeriesとDataFrame構造を示した図。"
      width="600"
      height="400"
      loading="lazy"
      decoding="async"
    />
    <figcaption>
      図：PandasのSeriesとDataFrameの関係を示している。
    </figcaption>
  </figure>

<pre class="line-numbers"><code class="language-python">
s = pd.Series([25, 30, 35], name=&#x27;Age&#x27;)
display(s)
</code></pre>

<div>
<style scoped>
    .dataframe tbody tr th:only-of-type {
        vertical-align: middle;
    }

    .dataframe tbody tr th {
        vertical-align: top;
    }

    .dataframe thead th {
        text-align: right;
    }
</style>
<table class="wp-block-table">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th>Age</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>0</th>
      <td>25</td>
    </tr>
    <tr>
      <th>1</th>
      <td>30</td>
    </tr>
    <tr>
      <th>2</th>
      <td>35</td>
    </tr>
  </tbody>
</table>
</div><br><label><b>dtype:</b> int64</label>

<h3><span id="toc17">Seriesの基本的な作り方</span></h3>
<p>Pandas Series も、pd.Series() メソッドを使って様々なデータ形式から作成できます。DataFrameの列が Series であることを理解するために、基本的な作成方法を簡単に見てみましょう。詳細な作成方法については、別の機会に詳しく解説します。</p>

<pre class="line-numbers"><code class="language-python">
# リストから作成する例
data_s_list = [10, 20, 30, 40]
series_from_list = pd.Series(data_s_list)
display(&#x27;リストから作成したSeries:&#x27;, series_from_list)

# 辞書から作成する例（インデックスを指定したい場合に便利）
data_s_dict = {&#x27;a&#x27;: 10, &#x27;b&#x27;: 20, &#x27;c&#x27;: 30, &#x27;d&#x27;: 40}
series_from_dict = pd.Series(data_s_dict)
display(&#x27;辞書から作成したSeries:&#x27;, series_from_dict)
</code></pre>

<p>&#8216;リストから作成したSeries:&#8217;</p>
<div>
<style scoped>
    .dataframe tbody tr th:only-of-type {
        vertical-align: middle;
    }

    .dataframe tbody tr th {
        vertical-align: top;
    }

    .dataframe thead th {
        text-align: right;
    }
</style>
<table class="wp-block-table">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th>0</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>0</th>
      <td>10</td>
    </tr>
    <tr>
      <th>1</th>
      <td>20</td>
    </tr>
    <tr>
      <th>2</th>
      <td>30</td>
    </tr>
    <tr>
      <th>3</th>
      <td>40</td>
    </tr>
  </tbody>
</table>
</div><br><label><b>dtype:</b> int64</label>
<p>&#8216;辞書から作成したSeries:&#8217;</p>

<div>
<style scoped>
    .dataframe tbody tr th:only-of-type {
        vertical-align: middle;
    }

    .dataframe tbody tr th {
        vertical-align: top;
    }

    .dataframe thead th {
        text-align: right;
    }
</style>
<table class="wp-block-table">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th>0</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>a</th>
      <td>10</td>
    </tr>
    <tr>
      <th>b</th>
      <td>20</td>
    </tr>
    <tr>
      <th>c</th>
      <td>30</td>
    </tr>
    <tr>
      <th>d</th>
      <td>40</td>
    </tr>
  </tbody>
</table>
</div><br><label><b>dtype:</b> int64</label>







<h3><span id="toc18">Series と DataFrame の決定的な違い（構造・次元・操作）</span></h3>
<ul>
<li>Series … 1次元（インデックス + 値）</li>
<li>DataFrame … 2次元（インデックス + 列 + 値）</li>
</ul>
<p>「行列（2次元表）なのか、1本の列なのか」というイメージを意識すると、 [] や loc / iloc を使ったときの挙動が理解しやすくなります。</p>

<h2><span id="toc19">初心者が必ずつまずく「[] と [[]] の違い」</span></h2>
<p>DataFrame から列を取り出すとき、次の2つの書き方がよく登場します。</p>

<pre class="line-numbers"><code class="language-python">
display(df[&#x27;Age&#x27;]) # Series（1次元）
display(df[[&#x27;Age&#x27;]]) # DataFrame（2次元）
</code></pre>

<div>
<style scoped>
    .dataframe tbody tr th:only-of-type {
        vertical-align: middle;
    }

    .dataframe tbody tr th {
        vertical-align: top;
    }

    .dataframe thead th {
        text-align: right;
    }
</style>
<table class="wp-block-table">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th>Age</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>0</th>
      <td>24</td>
    </tr>
    <tr>
      <th>1</th>
      <td>27</td>
    </tr>
    <tr>
      <th>2</th>
      <td>22</td>
    </tr>
    <tr>
      <th>3</th>
      <td>32</td>
    </tr>
    <tr>
      <th>4</th>
      <td>29</td>
    </tr>
  </tbody>
</table>
</div><br><label><b>dtype:</b> int64</label>


  <div id="df-1c6e8632-a8ff-444c-a689-82200a8f9c28" class="colab-df-container">
    <div>
<style scoped>
    .dataframe tbody tr th:only-of-type {
        vertical-align: middle;
    }

    .dataframe tbody tr th {
        vertical-align: top;
    }

    .dataframe thead th {
        text-align: right;
    }
</style>
<table class="wp-block-table">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th>Age</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>0</th>
      <td>24</td>
    </tr>
    <tr>
      <th>1</th>
      <td>27</td>
    </tr>
    <tr>
      <th>2</th>
      <td>22</td>
    </tr>
    <tr>
      <th>3</th>
      <td>32</td>
    </tr>
    <tr>
      <th>4</th>
      <td>29</td>
    </tr>
  </tbody>
</table>
</div>
    <div class="colab-df-buttons">

  <div class="colab-df-container">
    <button class="colab-df-convert" onclick="convertToInteractive('df-1c6e8632-a8ff-444c-a689-82200a8f9c28')"
            title="Convert this dataframe to an interactive table."
            style="display:none;">

  <svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 -960 960 960">
    <path d="M120-120v-720h720v720H120Zm60-500h600v-160H180v160Zm220 220h160v-160H400v160Zm0 220h160v-160H400v160ZM180-400h160v-160H180v160Zm440 0h160v-160H620v160ZM180-180h160v-160H180v160Zm440 0h160v-160H620v160Z"/>
  </svg>
    </button>

  <style>
    .colab-df-container {
      display:flex;
      gap: 12px;
    }

    .colab-df-convert {
      background-color: #E8F0FE;
      border: none;
      border-radius: 50%;
      cursor: pointer;
      display: none;
      fill: #1967D2;
      height: 32px;
      padding: 0 0 0 0;
      width: 32px;
    }

    .colab-df-convert:hover {
      background-color: #E2EBFA;
      box-shadow: 0px 1px 2px rgba(60, 64, 67, 0.3), 0px 1px 3px 1px rgba(60, 64, 67, 0.15);
      fill: #174EA6;
    }

    .colab-df-buttons div {
      margin-bottom: 4px;
    }

    [theme=dark] .colab-df-convert {
      background-color: #3B4455;
      fill: #D2E3FC;
    }

    [theme=dark] .colab-df-convert:hover {
      background-color: #434B5C;
      box-shadow: 0px 1px 3px 1px rgba(0, 0, 0, 0.15);
      filter: drop-shadow(0px 1px 2px rgba(0, 0, 0, 0.3));
      fill: #FFFFFF;
    }
  </style>

    <script>
      const buttonEl =
        document.querySelector('#df-1c6e8632-a8ff-444c-a689-82200a8f9c28 button.colab-df-convert');
      buttonEl.style.display =
        google.colab.kernel.accessAllowed ? 'block' : 'none';

      async function convertToInteractive(key) {
        const element = document.querySelector('#df-1c6e8632-a8ff-444c-a689-82200a8f9c28');
        const dataTable =
          await google.colab.kernel.invokeFunction('convertToInteractive',
                                                    [key], {});
        if (!dataTable) return;

        const docLinkHtml = 'Like what you see? Visit the ' +
          '<a target="_blank" href=https://colab.research.google.com/notebooks/data_table.ipynb>data table notebook</a>'
          + ' to learn more about interactive tables.';
        element.innerHTML = '';
        dataTable['output_type'] = 'display_data';
        await google.colab.output.renderOutput(dataTable, element);
        const docLink = document.createElement('div');
        docLink.innerHTML = docLinkHtml;
        element.appendChild(docLink);
      }
    </script>
  </div>


    <div id="df-77af3827-1ab9-4ac1-a02c-b79ce95f2f63">
      <button class="colab-df-quickchart" onclick="quickchart('df-77af3827-1ab9-4ac1-a02c-b79ce95f2f63')"
                title="Suggest charts"
                style="display:none;">

<svg xmlns="http://www.w3.org/2000/svg" height="24px"viewBox="0 0 24 24"
     width="24px">
    <g>
        <path d="M19 3H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zM9 17H7v-7h2v7zm4 0h-2V7h2v10zm4 0h-2v-4h2v4z"/>
    </g>
</svg>
      </button>

<style>
  .colab-df-quickchart {
      --bg-color: #E8F0FE;
      --fill-color: #1967D2;
      --hover-bg-color: #E2EBFA;
      --hover-fill-color: #174EA6;
      --disabled-fill-color: #AAA;
      --disabled-bg-color: #DDD;
  }

  [theme=dark] .colab-df-quickchart {
      --bg-color: #3B4455;
      --fill-color: #D2E3FC;
      --hover-bg-color: #434B5C;
      --hover-fill-color: #FFFFFF;
      --disabled-bg-color: #3B4455;
      --disabled-fill-color: #666;
  }

  .colab-df-quickchart {
    background-color: var(--bg-color);
    border: none;
    border-radius: 50%;
    cursor: pointer;
    display: none;
    fill: var(--fill-color);
    height: 32px;
    padding: 0;
    width: 32px;
  }

  .colab-df-quickchart:hover {
    background-color: var(--hover-bg-color);
    box-shadow: 0 1px 2px rgba(60, 64, 67, 0.3), 0 1px 3px 1px rgba(60, 64, 67, 0.15);
    fill: var(--button-hover-fill-color);
  }

  .colab-df-quickchart-complete:disabled,
  .colab-df-quickchart-complete:disabled:hover {
    background-color: var(--disabled-bg-color);
    fill: var(--disabled-fill-color);
    box-shadow: none;
  }

  .colab-df-spinner {
    border: 2px solid var(--fill-color);
    border-color: transparent;
    border-bottom-color: var(--fill-color);
    animation:
      spin 1s steps(1) infinite;
  }

  @keyframes spin {
    0% {
      border-color: transparent;
      border-bottom-color: var(--fill-color);
      border-left-color: var(--fill-color);
    }
    20% {
      border-color: transparent;
      border-left-color: var(--fill-color);
      border-top-color: var(--fill-color);
    }
    30% {
      border-color: transparent;
      border-left-color: var(--fill-color);
      border-top-color: var(--fill-color);
      border-right-color: var(--fill-color);
    }
    40% {
      border-color: transparent;
      border-right-color: var(--fill-color);
      border-top-color: var(--fill-color);
    }
    60% {
      border-color: transparent;
      border-right-color: var(--fill-color);
    }
    80% {
      border-color: transparent;
      border-right-color: var(--fill-color);
      border-bottom-color: var(--fill-color);
    }
    90% {
      border-color: transparent;
      border-bottom-color: var(--fill-color);
    }
  }
</style>

      <script>
        async function quickchart(key) {
          const quickchartButtonEl =
            document.querySelector('#' + key + ' button');
          quickchartButtonEl.disabled = true;  // To prevent multiple clicks.
          quickchartButtonEl.classList.add('colab-df-spinner');
          try {
            const charts = await google.colab.kernel.invokeFunction(
                'suggestCharts', [key], {});
          } catch (error) {
            console.error('Error during call to suggestCharts:', error);
          }
          quickchartButtonEl.classList.remove('colab-df-spinner');
          quickchartButtonEl.classList.add('colab-df-quickchart-complete');
        }
        (() => {
          let quickchartButtonEl =
            document.querySelector('#df-77af3827-1ab9-4ac1-a02c-b79ce95f2f63 button');
          quickchartButtonEl.style.display =
            google.colab.kernel.accessAllowed ? 'block' : 'none';
        })();
      </script>
    </div>

    </div>
  </div>


<p>最初は違いが分かりにくいですが、次のように覚えるとスッキリします。</p>
<ul>
<li>df[&#x27;col&#x27;] … 1本の列（Series）がほしいとき</li>
<li>df[[&#x27;col&#x27;]] … 列は1つでも「表（DataFrame）」として扱いたいとき</li>
</ul>
<p>一部のメソッド（ groupby や merge など）を使用する際は「DataFrameを渡すこと」を前提としているため、そのような場面では [[]] を使います。</p>

<h2><span id="toc20">最初に覚えたい10個の基本操作（DataFrame版チェックリスト）</span></h2>
<p>DataFrameのすべてを一気に覚える必要はありません。 まずは次の 10個の基本操作 だけ押さえておけば、入門〜基礎的な実務はほぼこなせます。</p>

<table>
<thead>
<tr>
<th>カテゴリ</th>
<th>代表的なメソッド・属性</th>
<th>何ができるか</th>
<th>詳しい解説記事</th>
</tr>
</thead>
<tbody>
<tr>
<td>① 中身を見る</td>
<td>
<code>df.head()</code>
,
<code>df.tail()</code>
</td>
<td>先頭・末尾の数行を確認して、全体のイメージをつかむ</td>
<td>
▶
<a href="https://pythondatalab.com/pandas-head/">head()/tail()で先頭・末尾を確認</a>
</td>
</tr>
<tr>
<td>② 構造・型を確認</td>
<td>
<code>df.info()</code>
,
<code>df.describe()</code>
,
<code>df.shape</code>
,
<code>df.dtypes</code>
</td>
<td>行数・列数、欠損、データ型、基本統計量をまとめてチェック</td>
<td>
▶
<a href="https://pythondatalab.com/pandas-info-describe/">info()/describe()で構造と統計量を確認</a>
</td>
</tr>
<tr>
<td>③ 行・列を指定して抽出</td>
<td>
<code>df["col"]</code>
,
<code>df[["col1","col2"]]</code>
,
<br/>
<code>df.loc[行ラベル, 列ラベル]</code>
,
<code>df.iloc[行番号, 列番号]</code>
</td>
<td>欲しい行・列だけを取り出す（1次元Seriesか2次元DataFrameかを意識）</td>
<td>
▶
<a href="https://pythondatalab.com/pandas-loc/">locでラベル抽出</a>
<br/>
▶
<a href="https://pythondatalab.com/pandas-iloc/">ilocで番号抽出</a>
<br/>
▶
<a href="https://pythondatalab.com/pandas-loc-iloc/">locとilocの違いと使い分け</a>
</td>
</tr>
<tr>
<td>④ 条件で絞り込む</td>
<td>
比較演算（
<code>==</code>
,
<code>></code>
等）、
<br/>
<code>&</code>
,
<code>|</code>
,
<code>~</code>
,
<code>isin()</code>
</td>
<td>「点数が80点以上」「都道府県が東京都 or 大阪府」などの条件で行を抽出</td>
<td>
▶
<a href="https://pythondatalab.com/pandas-filtering/">条件抽出・フィルタリング</a>
<br/>
▶
<a href="https://pythondatalab.com/pandas-isin/">isinで複数条件をまとめて抽出</a>
</td>
</tr>
<tr>
<td>⑤ 並び替える</td>
<td>
<code>df.sort_values()</code>
,
<code>df.sort_index()</code>
</td>
<td>売上の高い順、日付の新しい順などにソートして並び順を整える</td>
<td>
▶
<a href="https://pythondatalab.com/pandas-sort/">sort_values/sort_indexで並び替え</a>
</td>
</tr>
<tr>
<td>⑥ 列を追加・更新する</td>
<td>
<code>df["new_col"] = ...</code>
,
<code>assign()</code>
</td>
<td>合計点や平均点、フラグ列（True/False）などの派生列を作る</td>
<td>
▶ （列追加の詳細は
<a href="https://pythondatalab.com/pandas-drop/">drop/dropna記事</a>
も合わせて確認）
</td>
</tr>
<tr>
<td>⑦ 不要な行・列を削除</td>
<td>
<code>df.drop()</code>
,
<code>df.dropna()</code>
,
<code>df.drop_duplicates()</code>
</td>
<td>不要な列や欠損・重複を取り除き、分析しやすい形にする</td>
<td>
▶
<a href="https://pythondatalab.com/pandas-drop/">drop/dropna/drop_duplicatesで削除</a>
</td>
</tr>
<tr>
<td>⑧ グループごとに集計</td>
<td>
<code>df.groupby()</code>
,
<code>agg()</code>
,
<code>mean()</code>
,
<code>sum()</code>
</td>
<td>店舗ごとの売上合計、学年ごとの平均点など、カテゴリ別に集計する</td>
<td>
▶
<a href="https://pythondatalab.com/pandas-groupby-agg/">groupby/aggで集計</a>
</td>
</tr>
<tr>
<td>⑨ 表同士を結合・連結</td>
<td>
<code>pd.concat()</code>
,
<code>pd.merge()</code>
</td>
<td>同じ列構造の表を上下にくっつけたり、キー列を軸に結合したりする</td>
<td>
▶
<a href="https://pythondatalab.com/pandas-concat/">concatで縦横連結</a>
<br/>
▶
<a href="https://pythondatalab.com/pandas-merge/">mergeで結合</a>
</td>
</tr>
<tr>
<td>⑩ CSVファイルの読み書き</td>
<td>
<code>pd.read_csv()</code>
,
<code>df.to_csv()</code>
</td>
<td>CSVファイルから読み込んでDataFrameを作り、加工後のデータをCSVとして保存</td>
<td>
<br/>
▶
<a href="https://pythondatalab.com/google-colab-csv/">Google ColabでCSVを読み書き</a>
</td>
</tr>
</tbody>
</table>


<p>上の表を「チェックリスト」として使い、1つずつ実際のデータで試してみるのがおすすめです。 すべてのメソッドを完璧に覚える必要はなく、 「こんなときにこのメソッドを使う」 という対応関係だけ押さえておけば十分です。</p>


<h2><span id="toc21">ミニ演習：DataFrameの基本操作を手を動かして確認しよう</span></h2>
<p>最後に、この記事で紹介した内容を小さなデータセットで試してみましょう。 以下のコードでサンプルDataFrame df_students を作成します。</p>

<pre class="line-numbers"><code class="language-python">
import pandas as pd
data = { &#x27;name&#x27;: [&#x27;Alice&#x27;, &#x27;Bob&#x27;, &#x27;Charlie&#x27;, &#x27;David&#x27;, &#x27;Eve&#x27;],
         &#x27;math&#x27;: [80, 65, 90, 70, 85],
         &#x27;english&#x27;: [75, 88, 92, 60, 78],
         &#x27;class&#x27;: [&#x27;A&#x27;, &#x27;B&#x27;, &#x27;A&#x27;, &#x27;B&#x27;, &#x27;A&#x27;]
        }
df_students = pd.DataFrame(data)
display(df_students)
</code></pre>


  <div id="df-02aa8bc9-b173-45d2-8c23-ae7b7b2e31b2" class="colab-df-container">
    <div>
<style scoped>
    .dataframe tbody tr th:only-of-type {
        vertical-align: middle;
    }

    .dataframe tbody tr th {
        vertical-align: top;
    }

    .dataframe thead th {
        text-align: right;
    }
</style>
<table class="wp-block-table">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th>name</th>
      <th>math</th>
      <th>english</th>
      <th>class</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>0</th>
      <td>Alice</td>
      <td>80</td>
      <td>75</td>
      <td>A</td>
    </tr>
    <tr>
      <th>1</th>
      <td>Bob</td>
      <td>65</td>
      <td>88</td>
      <td>B</td>
    </tr>
    <tr>
      <th>2</th>
      <td>Charlie</td>
      <td>90</td>
      <td>92</td>
      <td>A</td>
    </tr>
    <tr>
      <th>3</th>
      <td>David</td>
      <td>70</td>
      <td>60</td>
      <td>B</td>
    </tr>
    <tr>
      <th>4</th>
      <td>Eve</td>
      <td>85</td>
      <td>78</td>
      <td>A</td>
    </tr>
  </tbody>
</table>
</div>
    <div class="colab-df-buttons">

  <div class="colab-df-container">
    <button class="colab-df-convert" onclick="convertToInteractive('df-02aa8bc9-b173-45d2-8c23-ae7b7b2e31b2')"
            title="Convert this dataframe to an interactive table."
            style="display:none;">

  <svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 -960 960 960">
    <path d="M120-120v-720h720v720H120Zm60-500h600v-160H180v160Zm220 220h160v-160H400v160Zm0 220h160v-160H400v160ZM180-400h160v-160H180v160Zm440 0h160v-160H620v160ZM180-180h160v-160H180v160Zm440 0h160v-160H620v160Z"/>
  </svg>
    </button>

  <style>
    .colab-df-container {
      display:flex;
      gap: 12px;
    }

    .colab-df-convert {
      background-color: #E8F0FE;
      border: none;
      border-radius: 50%;
      cursor: pointer;
      display: none;
      fill: #1967D2;
      height: 32px;
      padding: 0 0 0 0;
      width: 32px;
    }

    .colab-df-convert:hover {
      background-color: #E2EBFA;
      box-shadow: 0px 1px 2px rgba(60, 64, 67, 0.3), 0px 1px 3px 1px rgba(60, 64, 67, 0.15);
      fill: #174EA6;
    }

    .colab-df-buttons div {
      margin-bottom: 4px;
    }

    [theme=dark] .colab-df-convert {
      background-color: #3B4455;
      fill: #D2E3FC;
    }

    [theme=dark] .colab-df-convert:hover {
      background-color: #434B5C;
      box-shadow: 0px 1px 3px 1px rgba(0, 0, 0, 0.15);
      filter: drop-shadow(0px 1px 2px rgba(0, 0, 0, 0.3));
      fill: #FFFFFF;
    }
  </style>

    <script>
      const buttonEl =
        document.querySelector('#df-02aa8bc9-b173-45d2-8c23-ae7b7b2e31b2 button.colab-df-convert');
      buttonEl.style.display =
        google.colab.kernel.accessAllowed ? 'block' : 'none';

      async function convertToInteractive(key) {
        const element = document.querySelector('#df-02aa8bc9-b173-45d2-8c23-ae7b7b2e31b2');
        const dataTable =
          await google.colab.kernel.invokeFunction('convertToInteractive',
                                                    [key], {});
        if (!dataTable) return;

        const docLinkHtml = 'Like what you see? Visit the ' +
          '<a target="_blank" href=https://colab.research.google.com/notebooks/data_table.ipynb>data table notebook</a>'
          + ' to learn more about interactive tables.';
        element.innerHTML = '';
        dataTable['output_type'] = 'display_data';
        await google.colab.output.renderOutput(dataTable, element);
        const docLink = document.createElement('div');
        docLink.innerHTML = docLinkHtml;
        element.appendChild(docLink);
      }
    </script>
  </div>


    <div id="df-deccdff9-4852-484c-91d5-3cda209ba8c8">
      <button class="colab-df-quickchart" onclick="quickchart('df-deccdff9-4852-484c-91d5-3cda209ba8c8')"
                title="Suggest charts"
                style="display:none;">

<svg xmlns="http://www.w3.org/2000/svg" height="24px"viewBox="0 0 24 24"
     width="24px">
    <g>
        <path d="M19 3H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zM9 17H7v-7h2v7zm4 0h-2V7h2v10zm4 0h-2v-4h2v4z"/>
    </g>
</svg>
      </button>

<style>
  .colab-df-quickchart {
      --bg-color: #E8F0FE;
      --fill-color: #1967D2;
      --hover-bg-color: #E2EBFA;
      --hover-fill-color: #174EA6;
      --disabled-fill-color: #AAA;
      --disabled-bg-color: #DDD;
  }

  [theme=dark] .colab-df-quickchart {
      --bg-color: #3B4455;
      --fill-color: #D2E3FC;
      --hover-bg-color: #434B5C;
      --hover-fill-color: #FFFFFF;
      --disabled-bg-color: #3B4455;
      --disabled-fill-color: #666;
  }

  .colab-df-quickchart {
    background-color: var(--bg-color);
    border: none;
    border-radius: 50%;
    cursor: pointer;
    display: none;
    fill: var(--fill-color);
    height: 32px;
    padding: 0;
    width: 32px;
  }

  .colab-df-quickchart:hover {
    background-color: var(--hover-bg-color);
    box-shadow: 0 1px 2px rgba(60, 64, 67, 0.3), 0 1px 3px 1px rgba(60, 64, 67, 0.15);
    fill: var(--button-hover-fill-color);
  }

  .colab-df-quickchart-complete:disabled,
  .colab-df-quickchart-complete:disabled:hover {
    background-color: var(--disabled-bg-color);
    fill: var(--disabled-fill-color);
    box-shadow: none;
  }

  .colab-df-spinner {
    border: 2px solid var(--fill-color);
    border-color: transparent;
    border-bottom-color: var(--fill-color);
    animation:
      spin 1s steps(1) infinite;
  }

  @keyframes spin {
    0% {
      border-color: transparent;
      border-bottom-color: var(--fill-color);
      border-left-color: var(--fill-color);
    }
    20% {
      border-color: transparent;
      border-left-color: var(--fill-color);
      border-top-color: var(--fill-color);
    }
    30% {
      border-color: transparent;
      border-left-color: var(--fill-color);
      border-top-color: var(--fill-color);
      border-right-color: var(--fill-color);
    }
    40% {
      border-color: transparent;
      border-right-color: var(--fill-color);
      border-top-color: var(--fill-color);
    }
    60% {
      border-color: transparent;
      border-right-color: var(--fill-color);
    }
    80% {
      border-color: transparent;
      border-right-color: var(--fill-color);
      border-bottom-color: var(--fill-color);
    }
    90% {
      border-color: transparent;
      border-bottom-color: var(--fill-color);
    }
  }
</style>

      <script>
        async function quickchart(key) {
          const quickchartButtonEl =
            document.querySelector('#' + key + ' button');
          quickchartButtonEl.disabled = true;  // To prevent multiple clicks.
          quickchartButtonEl.classList.add('colab-df-spinner');
          try {
            const charts = await google.colab.kernel.invokeFunction(
                'suggestCharts', [key], {});
          } catch (error) {
            console.error('Error during call to suggestCharts:', error);
          }
          quickchartButtonEl.classList.remove('colab-df-spinner');
          quickchartButtonEl.classList.add('colab-df-quickchart-complete');
        }
        (() => {
          let quickchartButtonEl =
            document.querySelector('#df-deccdff9-4852-484c-91d5-3cda209ba8c8 button');
          quickchartButtonEl.style.display =
            google.colab.kernel.accessAllowed ? 'block' : 'none';
        })();
      </script>
    </div>

  <div id="id_e0b7d299-b3c1-4b2f-9d77-77802ada88a6">
    <style>
      .colab-df-generate {
        background-color: #E8F0FE;
        border: none;
        border-radius: 50%;
        cursor: pointer;
        display: none;
        fill: #1967D2;
        height: 32px;
        padding: 0 0 0 0;
        width: 32px;
      }

      .colab-df-generate:hover {
        background-color: #E2EBFA;
        box-shadow: 0px 1px 2px rgba(60, 64, 67, 0.3), 0px 1px 3px 1px rgba(60, 64, 67, 0.15);
        fill: #174EA6;
      }

      [theme=dark] .colab-df-generate {
        background-color: #3B4455;
        fill: #D2E3FC;
      }

      [theme=dark] .colab-df-generate:hover {
        background-color: #434B5C;
        box-shadow: 0px 1px 3px 1px rgba(0, 0, 0, 0.15);
        filter: drop-shadow(0px 1px 2px rgba(0, 0, 0, 0.3));
        fill: #FFFFFF;
      }
    </style>
    <button class="colab-df-generate" onclick="generateWithVariable('df_students')"
            title="Generate code using this dataframe."
            style="display:none;">

  <svg xmlns="http://www.w3.org/2000/svg" height="24px"viewBox="0 0 24 24"
       width="24px">
    <path d="M7,19H8.4L18.45,9,17,7.55,7,17.6ZM5,21V16.75L18.45,3.32a2,2,0,0,1,2.83,0l1.4,1.43a1.91,1.91,0,0,1,.58,1.4,1.91,1.91,0,0,1-.58,1.4L9.25,21ZM18.45,9,17,7.55Zm-12,3A5.31,5.31,0,0,0,4.9,8.1,5.31,5.31,0,0,0,1,6.5,5.31,5.31,0,0,0,4.9,4.9,5.31,5.31,0,0,0,6.5,1,5.31,5.31,0,0,0,8.1,4.9,5.31,5.31,0,0,0,12,6.5,5.46,5.46,0,0,0,6.5,12Z"/>
  </svg>
    </button>
    <script>
      (() => {
      const buttonEl =
        document.querySelector('#id_e0b7d299-b3c1-4b2f-9d77-77802ada88a6 button.colab-df-generate');
      buttonEl.style.display =
        google.colab.kernel.accessAllowed ? 'block' : 'none';

      buttonEl.onclick = () => {
        google.colab.notebook.generateWithVariable('df_students');
      }
      })();
    </script>
  </div>

    </div>
  </div>


<p>この df_students を使って、次の問題を解いてみてください。</p>
<ul>
<li>先頭3行だけを確認 してみましょう。</li>
<li>行数・列数・列名・データ型 をそれぞれ1行ずつで確認してみましょう。</li>
<li>数学の点数が80点以上 の行だけを抽出してみましょう。</li>
<li>各クラスごとの数学の平均点 を求めてみましょう。</li>
<li>総合点（math + english） の列を追加し、総合点の高い順に並び替えてみましょう。</li>
</ul>

<h3><span id="toc22">解答例（一例）</span></h3>

<pre class="line-numbers"><code class="language-python">
# 1. 先頭3行
display(df_students.head(3))

# 2. 構造・型の確認
# (行数, 列数)
display(df_students.shape)
# 列名
display(df_students.columns)
# 各列のデータ型
display(df_students.dtypes)
# まとめて確認
display(df_students.info())

# 3. 数学が80点以上の行を抽出
display(df_students[df_students[&#x27;math&#x27;] &gt;= 80])
# 4. クラスごとの数学の平均点
display(df_students.groupby(&#x27;class&#x27;)[&#x27;math&#x27;].mean())
# 5. 総合点の列を追加し、高い順に並び替え
df_students[&#x27;total&#x27;] = df_students[&#x27;math&#x27;] + df_students[&#x27;english&#x27;]
df_sorted = df_students.sort_values(&#x27;total&#x27;, ascending=False)
display(df_sorted)
</code></pre>


  <div id="df-ae616287-43db-428f-ae1d-d56cc09506f5" class="colab-df-container">
    <div>
<style scoped>
    .dataframe tbody tr th:only-of-type {
        vertical-align: middle;
    }

    .dataframe tbody tr th {
        vertical-align: top;
    }

    .dataframe thead th {
        text-align: right;
    }
</style>
<table class="wp-block-table">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th>name</th>
      <th>math</th>
      <th>english</th>
      <th>class</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>0</th>
      <td>Alice</td>
      <td>80</td>
      <td>75</td>
      <td>A</td>
    </tr>
    <tr>
      <th>1</th>
      <td>Bob</td>
      <td>65</td>
      <td>88</td>
      <td>B</td>
    </tr>
    <tr>
      <th>2</th>
      <td>Charlie</td>
      <td>90</td>
      <td>92</td>
      <td>A</td>
    </tr>
  </tbody>
</table>
</div>
    <div class="colab-df-buttons">

  <div class="colab-df-container">
    <button class="colab-df-convert" onclick="convertToInteractive('df-ae616287-43db-428f-ae1d-d56cc09506f5')"
            title="Convert this dataframe to an interactive table."
            style="display:none;">

  <svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 -960 960 960">
    <path d="M120-120v-720h720v720H120Zm60-500h600v-160H180v160Zm220 220h160v-160H400v160Zm0 220h160v-160H400v160ZM180-400h160v-160H180v160Zm440 0h160v-160H620v160ZM180-180h160v-160H180v160Zm440 0h160v-160H620v160Z"/>
  </svg>
    </button>

  <style>
    .colab-df-container {
      display:flex;
      gap: 12px;
    }

    .colab-df-convert {
      background-color: #E8F0FE;
      border: none;
      border-radius: 50%;
      cursor: pointer;
      display: none;
      fill: #1967D2;
      height: 32px;
      padding: 0 0 0 0;
      width: 32px;
    }

    .colab-df-convert:hover {
      background-color: #E2EBFA;
      box-shadow: 0px 1px 2px rgba(60, 64, 67, 0.3), 0px 1px 3px 1px rgba(60, 64, 67, 0.15);
      fill: #174EA6;
    }

    .colab-df-buttons div {
      margin-bottom: 4px;
    }

    [theme=dark] .colab-df-convert {
      background-color: #3B4455;
      fill: #D2E3FC;
    }

    [theme=dark] .colab-df-convert:hover {
      background-color: #434B5C;
      box-shadow: 0px 1px 3px 1px rgba(0, 0, 0, 0.15);
      filter: drop-shadow(0px 1px 2px rgba(0, 0, 0, 0.3));
      fill: #FFFFFF;
    }
  </style>

    <script>
      const buttonEl =
        document.querySelector('#df-ae616287-43db-428f-ae1d-d56cc09506f5 button.colab-df-convert');
      buttonEl.style.display =
        google.colab.kernel.accessAllowed ? 'block' : 'none';

      async function convertToInteractive(key) {
        const element = document.querySelector('#df-ae616287-43db-428f-ae1d-d56cc09506f5');
        const dataTable =
          await google.colab.kernel.invokeFunction('convertToInteractive',
                                                    [key], {});
        if (!dataTable) return;

        const docLinkHtml = 'Like what you see? Visit the ' +
          '<a target="_blank" href=https://colab.research.google.com/notebooks/data_table.ipynb>data table notebook</a>'
          + ' to learn more about interactive tables.';
        element.innerHTML = '';
        dataTable['output_type'] = 'display_data';
        await google.colab.output.renderOutput(dataTable, element);
        const docLink = document.createElement('div');
        docLink.innerHTML = docLinkHtml;
        element.appendChild(docLink);
      }
    </script>
  </div>


    <div id="df-0b629e52-e35e-4b2a-a825-8364b5581d71">
      <button class="colab-df-quickchart" onclick="quickchart('df-0b629e52-e35e-4b2a-a825-8364b5581d71')"
                title="Suggest charts"
                style="display:none;">

<svg xmlns="http://www.w3.org/2000/svg" height="24px"viewBox="0 0 24 24"
     width="24px">
    <g>
        <path d="M19 3H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zM9 17H7v-7h2v7zm4 0h-2V7h2v10zm4 0h-2v-4h2v4z"/>
    </g>
</svg>
      </button>

<style>
  .colab-df-quickchart {
      --bg-color: #E8F0FE;
      --fill-color: #1967D2;
      --hover-bg-color: #E2EBFA;
      --hover-fill-color: #174EA6;
      --disabled-fill-color: #AAA;
      --disabled-bg-color: #DDD;
  }

  [theme=dark] .colab-df-quickchart {
      --bg-color: #3B4455;
      --fill-color: #D2E3FC;
      --hover-bg-color: #434B5C;
      --hover-fill-color: #FFFFFF;
      --disabled-bg-color: #3B4455;
      --disabled-fill-color: #666;
  }

  .colab-df-quickchart {
    background-color: var(--bg-color);
    border: none;
    border-radius: 50%;
    cursor: pointer;
    display: none;
    fill: var(--fill-color);
    height: 32px;
    padding: 0;
    width: 32px;
  }

  .colab-df-quickchart:hover {
    background-color: var(--hover-bg-color);
    box-shadow: 0 1px 2px rgba(60, 64, 67, 0.3), 0 1px 3px 1px rgba(60, 64, 67, 0.15);
    fill: var(--button-hover-fill-color);
  }

  .colab-df-quickchart-complete:disabled,
  .colab-df-quickchart-complete:disabled:hover {
    background-color: var(--disabled-bg-color);
    fill: var(--disabled-fill-color);
    box-shadow: none;
  }

  .colab-df-spinner {
    border: 2px solid var(--fill-color);
    border-color: transparent;
    border-bottom-color: var(--fill-color);
    animation:
      spin 1s steps(1) infinite;
  }

  @keyframes spin {
    0% {
      border-color: transparent;
      border-bottom-color: var(--fill-color);
      border-left-color: var(--fill-color);
    }
    20% {
      border-color: transparent;
      border-left-color: var(--fill-color);
      border-top-color: var(--fill-color);
    }
    30% {
      border-color: transparent;
      border-left-color: var(--fill-color);
      border-top-color: var(--fill-color);
      border-right-color: var(--fill-color);
    }
    40% {
      border-color: transparent;
      border-right-color: var(--fill-color);
      border-top-color: var(--fill-color);
    }
    60% {
      border-color: transparent;
      border-right-color: var(--fill-color);
    }
    80% {
      border-color: transparent;
      border-right-color: var(--fill-color);
      border-bottom-color: var(--fill-color);
    }
    90% {
      border-color: transparent;
      border-bottom-color: var(--fill-color);
    }
  }
</style>

      <script>
        async function quickchart(key) {
          const quickchartButtonEl =
            document.querySelector('#' + key + ' button');
          quickchartButtonEl.disabled = true;  // To prevent multiple clicks.
          quickchartButtonEl.classList.add('colab-df-spinner');
          try {
            const charts = await google.colab.kernel.invokeFunction(
                'suggestCharts', [key], {});
          } catch (error) {
            console.error('Error during call to suggestCharts:', error);
          }
          quickchartButtonEl.classList.remove('colab-df-spinner');
          quickchartButtonEl.classList.add('colab-df-quickchart-complete');
        }
        (() => {
          let quickchartButtonEl =
            document.querySelector('#df-0b629e52-e35e-4b2a-a825-8364b5581d71 button');
          quickchartButtonEl.style.display =
            google.colab.kernel.accessAllowed ? 'block' : 'none';
        })();
      </script>
    </div>

    </div>
  </div>


<div>
<style scoped>
    .dataframe tbody tr th:only-of-type {
        vertical-align: middle;
    }

    .dataframe tbody tr th {
        vertical-align: top;
    }

    .dataframe thead th {
        text-align: right;
    }
</style>
<table class="wp-block-table">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th>0</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>name</th>
      <td>object</td>
    </tr>
    <tr>
      <th>math</th>
      <td>int64</td>
    </tr>
    <tr>
      <th>english</th>
      <td>int64</td>
    </tr>
    <tr>
      <th>class</th>
      <td>object</td>
    </tr>
  </tbody>
</table>
</div><br><label><b>dtype:</b> object</label>


  <div id="df-d260571c-8200-459a-826f-7d4bb7695640" class="colab-df-container">
    <div>
<style scoped>
    .dataframe tbody tr th:only-of-type {
        vertical-align: middle;
    }

    .dataframe tbody tr th {
        vertical-align: top;
    }

    .dataframe thead th {
        text-align: right;
    }
</style>
<table class="wp-block-table">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th>name</th>
      <th>math</th>
      <th>english</th>
      <th>class</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>0</th>
      <td>Alice</td>
      <td>80</td>
      <td>75</td>
      <td>A</td>
    </tr>
    <tr>
      <th>2</th>
      <td>Charlie</td>
      <td>90</td>
      <td>92</td>
      <td>A</td>
    </tr>
    <tr>
      <th>4</th>
      <td>Eve</td>
      <td>85</td>
      <td>78</td>
      <td>A</td>
    </tr>
  </tbody>
</table>
</div>
    <div class="colab-df-buttons">

  <div class="colab-df-container">
    <button class="colab-df-convert" onclick="convertToInteractive('df-d260571c-8200-459a-826f-7d4bb7695640')"
            title="Convert this dataframe to an interactive table."
            style="display:none;">

  <svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 -960 960 960">
    <path d="M120-120v-720h720v720H120Zm60-500h600v-160H180v160Zm220 220h160v-160H400v160Zm0 220h160v-160H400v160ZM180-400h160v-160H180v160Zm440 0h160v-160H620v160ZM180-180h160v-160H180v160Zm440 0h160v-160H620v160Z"/>
  </svg>
    </button>

  <style>
    .colab-df-container {
      display:flex;
      gap: 12px;
    }

    .colab-df-convert {
      background-color: #E8F0FE;
      border: none;
      border-radius: 50%;
      cursor: pointer;
      display: none;
      fill: #1967D2;
      height: 32px;
      padding: 0 0 0 0;
      width: 32px;
    }

    .colab-df-convert:hover {
      background-color: #E2EBFA;
      box-shadow: 0px 1px 2px rgba(60, 64, 67, 0.3), 0px 1px 3px 1px rgba(60, 64, 67, 0.15);
      fill: #174EA6;
    }

    .colab-df-buttons div {
      margin-bottom: 4px;
    }

    [theme=dark] .colab-df-convert {
      background-color: #3B4455;
      fill: #D2E3FC;
    }

    [theme=dark] .colab-df-convert:hover {
      background-color: #434B5C;
      box-shadow: 0px 1px 3px 1px rgba(0, 0, 0, 0.15);
      filter: drop-shadow(0px 1px 2px rgba(0, 0, 0, 0.3));
      fill: #FFFFFF;
    }
  </style>

    <script>
      const buttonEl =
        document.querySelector('#df-d260571c-8200-459a-826f-7d4bb7695640 button.colab-df-convert');
      buttonEl.style.display =
        google.colab.kernel.accessAllowed ? 'block' : 'none';

      async function convertToInteractive(key) {
        const element = document.querySelector('#df-d260571c-8200-459a-826f-7d4bb7695640');
        const dataTable =
          await google.colab.kernel.invokeFunction('convertToInteractive',
                                                    [key], {});
        if (!dataTable) return;

        const docLinkHtml = 'Like what you see? Visit the ' +
          '<a target="_blank" href=https://colab.research.google.com/notebooks/data_table.ipynb>data table notebook</a>'
          + ' to learn more about interactive tables.';
        element.innerHTML = '';
        dataTable['output_type'] = 'display_data';
        await google.colab.output.renderOutput(dataTable, element);
        const docLink = document.createElement('div');
        docLink.innerHTML = docLinkHtml;
        element.appendChild(docLink);
      }
    </script>
  </div>


    <div id="df-e1b4a431-b19f-4039-99da-15e12feb8354">
      <button class="colab-df-quickchart" onclick="quickchart('df-e1b4a431-b19f-4039-99da-15e12feb8354')"
                title="Suggest charts"
                style="display:none;">

<svg xmlns="http://www.w3.org/2000/svg" height="24px"viewBox="0 0 24 24"
     width="24px">
    <g>
        <path d="M19 3H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zM9 17H7v-7h2v7zm4 0h-2V7h2v10zm4 0h-2v-4h2v4z"/>
    </g>
</svg>
      </button>

<style>
  .colab-df-quickchart {
      --bg-color: #E8F0FE;
      --fill-color: #1967D2;
      --hover-bg-color: #E2EBFA;
      --hover-fill-color: #174EA6;
      --disabled-fill-color: #AAA;
      --disabled-bg-color: #DDD;
  }

  [theme=dark] .colab-df-quickchart {
      --bg-color: #3B4455;
      --fill-color: #D2E3FC;
      --hover-bg-color: #434B5C;
      --hover-fill-color: #FFFFFF;
      --disabled-bg-color: #3B4455;
      --disabled-fill-color: #666;
  }

  .colab-df-quickchart {
    background-color: var(--bg-color);
    border: none;
    border-radius: 50%;
    cursor: pointer;
    display: none;
    fill: var(--fill-color);
    height: 32px;
    padding: 0;
    width: 32px;
  }

  .colab-df-quickchart:hover {
    background-color: var(--hover-bg-color);
    box-shadow: 0 1px 2px rgba(60, 64, 67, 0.3), 0 1px 3px 1px rgba(60, 64, 67, 0.15);
    fill: var(--button-hover-fill-color);
  }

  .colab-df-quickchart-complete:disabled,
  .colab-df-quickchart-complete:disabled:hover {
    background-color: var(--disabled-bg-color);
    fill: var(--disabled-fill-color);
    box-shadow: none;
  }

  .colab-df-spinner {
    border: 2px solid var(--fill-color);
    border-color: transparent;
    border-bottom-color: var(--fill-color);
    animation:
      spin 1s steps(1) infinite;
  }

  @keyframes spin {
    0% {
      border-color: transparent;
      border-bottom-color: var(--fill-color);
      border-left-color: var(--fill-color);
    }
    20% {
      border-color: transparent;
      border-left-color: var(--fill-color);
      border-top-color: var(--fill-color);
    }
    30% {
      border-color: transparent;
      border-left-color: var(--fill-color);
      border-top-color: var(--fill-color);
      border-right-color: var(--fill-color);
    }
    40% {
      border-color: transparent;
      border-right-color: var(--fill-color);
      border-top-color: var(--fill-color);
    }
    60% {
      border-color: transparent;
      border-right-color: var(--fill-color);
    }
    80% {
      border-color: transparent;
      border-right-color: var(--fill-color);
      border-bottom-color: var(--fill-color);
    }
    90% {
      border-color: transparent;
      border-bottom-color: var(--fill-color);
    }
  }
</style>

      <script>
        async function quickchart(key) {
          const quickchartButtonEl =
            document.querySelector('#' + key + ' button');
          quickchartButtonEl.disabled = true;  // To prevent multiple clicks.
          quickchartButtonEl.classList.add('colab-df-spinner');
          try {
            const charts = await google.colab.kernel.invokeFunction(
                'suggestCharts', [key], {});
          } catch (error) {
            console.error('Error during call to suggestCharts:', error);
          }
          quickchartButtonEl.classList.remove('colab-df-spinner');
          quickchartButtonEl.classList.add('colab-df-quickchart-complete');
        }
        (() => {
          let quickchartButtonEl =
            document.querySelector('#df-e1b4a431-b19f-4039-99da-15e12feb8354 button');
          quickchartButtonEl.style.display =
            google.colab.kernel.accessAllowed ? 'block' : 'none';
        })();
      </script>
    </div>

    </div>
  </div>


<div>
<style scoped>
    .dataframe tbody tr th:only-of-type {
        vertical-align: middle;
    }

    .dataframe tbody tr th {
        vertical-align: top;
    }

    .dataframe thead th {
        text-align: right;
    }
</style>
<table class="wp-block-table">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th>math</th>
    </tr>
    <tr>
      <th>class</th>
      <th></th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>A</th>
      <td>85.0</td>
    </tr>
    <tr>
      <th>B</th>
      <td>67.5</td>
    </tr>
  </tbody>
</table>
</div><br><label><b>dtype:</b> float64</label>


  <div id="df-5df0573e-cc28-4e3c-b27b-c052dcdfe152" class="colab-df-container">
    <div>
<style scoped>
    .dataframe tbody tr th:only-of-type {
        vertical-align: middle;
    }

    .dataframe tbody tr th {
        vertical-align: top;
    }

    .dataframe thead th {
        text-align: right;
    }
</style>
<table class="wp-block-table">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th>name</th>
      <th>math</th>
      <th>english</th>
      <th>class</th>
      <th>total</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>2</th>
      <td>Charlie</td>
      <td>90</td>
      <td>92</td>
      <td>A</td>
      <td>182</td>
    </tr>
    <tr>
      <th>4</th>
      <td>Eve</td>
      <td>85</td>
      <td>78</td>
      <td>A</td>
      <td>163</td>
    </tr>
    <tr>
      <th>0</th>
      <td>Alice</td>
      <td>80</td>
      <td>75</td>
      <td>A</td>
      <td>155</td>
    </tr>
    <tr>
      <th>1</th>
      <td>Bob</td>
      <td>65</td>
      <td>88</td>
      <td>B</td>
      <td>153</td>
    </tr>
    <tr>
      <th>3</th>
      <td>David</td>
      <td>70</td>
      <td>60</td>
      <td>B</td>
      <td>130</td>
    </tr>
  </tbody>
</table>
</div>
    <div class="colab-df-buttons">

  <div class="colab-df-container">
    <button class="colab-df-convert" onclick="convertToInteractive('df-5df0573e-cc28-4e3c-b27b-c052dcdfe152')"
            title="Convert this dataframe to an interactive table."
            style="display:none;">

  <svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 -960 960 960">
    <path d="M120-120v-720h720v720H120Zm60-500h600v-160H180v160Zm220 220h160v-160H400v160Zm0 220h160v-160H400v160ZM180-400h160v-160H180v160Zm440 0h160v-160H620v160ZM180-180h160v-160H180v160Zm440 0h160v-160H620v160Z"/>
  </svg>
    </button>

  <style>
    .colab-df-container {
      display:flex;
      gap: 12px;
    }

    .colab-df-convert {
      background-color: #E8F0FE;
      border: none;
      border-radius: 50%;
      cursor: pointer;
      display: none;
      fill: #1967D2;
      height: 32px;
      padding: 0 0 0 0;
      width: 32px;
    }

    .colab-df-convert:hover {
      background-color: #E2EBFA;
      box-shadow: 0px 1px 2px rgba(60, 64, 67, 0.3), 0px 1px 3px 1px rgba(60, 64, 67, 0.15);
      fill: #174EA6;
    }

    .colab-df-buttons div {
      margin-bottom: 4px;
    }

    [theme=dark] .colab-df-convert {
      background-color: #3B4455;
      fill: #D2E3FC;
    }

    [theme=dark] .colab-df-convert:hover {
      background-color: #434B5C;
      box-shadow: 0px 1px 3px 1px rgba(0, 0, 0, 0.15);
      filter: drop-shadow(0px 1px 2px rgba(0, 0, 0, 0.3));
      fill: #FFFFFF;
    }
  </style>

    <script>
      const buttonEl =
        document.querySelector('#df-5df0573e-cc28-4e3c-b27b-c052dcdfe152 button.colab-df-convert');
      buttonEl.style.display =
        google.colab.kernel.accessAllowed ? 'block' : 'none';

      async function convertToInteractive(key) {
        const element = document.querySelector('#df-5df0573e-cc28-4e3c-b27b-c052dcdfe152');
        const dataTable =
          await google.colab.kernel.invokeFunction('convertToInteractive',
                                                    [key], {});
        if (!dataTable) return;

        const docLinkHtml = 'Like what you see? Visit the ' +
          '<a target="_blank" href=https://colab.research.google.com/notebooks/data_table.ipynb>data table notebook</a>'
          + ' to learn more about interactive tables.';
        element.innerHTML = '';
        dataTable['output_type'] = 'display_data';
        await google.colab.output.renderOutput(dataTable, element);
        const docLink = document.createElement('div');
        docLink.innerHTML = docLinkHtml;
        element.appendChild(docLink);
      }
    </script>
  </div>


    <div id="df-847b3c03-77d4-4550-9c47-0d1e7e39ce17">
      <button class="colab-df-quickchart" onclick="quickchart('df-847b3c03-77d4-4550-9c47-0d1e7e39ce17')"
                title="Suggest charts"
                style="display:none;">

<svg xmlns="http://www.w3.org/2000/svg" height="24px"viewBox="0 0 24 24"
     width="24px">
    <g>
        <path d="M19 3H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zM9 17H7v-7h2v7zm4 0h-2V7h2v10zm4 0h-2v-4h2v4z"/>
    </g>
</svg>
      </button>

<style>
  .colab-df-quickchart {
      --bg-color: #E8F0FE;
      --fill-color: #1967D2;
      --hover-bg-color: #E2EBFA;
      --hover-fill-color: #174EA6;
      --disabled-fill-color: #AAA;
      --disabled-bg-color: #DDD;
  }

  [theme=dark] .colab-df-quickchart {
      --bg-color: #3B4455;
      --fill-color: #D2E3FC;
      --hover-bg-color: #434B5C;
      --hover-fill-color: #FFFFFF;
      --disabled-bg-color: #3B4455;
      --disabled-fill-color: #666;
  }

  .colab-df-quickchart {
    background-color: var(--bg-color);
    border: none;
    border-radius: 50%;
    cursor: pointer;
    display: none;
    fill: var(--fill-color);
    height: 32px;
    padding: 0;
    width: 32px;
  }

  .colab-df-quickchart:hover {
    background-color: var(--hover-bg-color);
    box-shadow: 0 1px 2px rgba(60, 64, 67, 0.3), 0 1px 3px 1px rgba(60, 64, 67, 0.15);
    fill: var(--button-hover-fill-color);
  }

  .colab-df-quickchart-complete:disabled,
  .colab-df-quickchart-complete:disabled:hover {
    background-color: var(--disabled-bg-color);
    fill: var(--disabled-fill-color);
    box-shadow: none;
  }

  .colab-df-spinner {
    border: 2px solid var(--fill-color);
    border-color: transparent;
    border-bottom-color: var(--fill-color);
    animation:
      spin 1s steps(1) infinite;
  }

  @keyframes spin {
    0% {
      border-color: transparent;
      border-bottom-color: var(--fill-color);
      border-left-color: var(--fill-color);
    }
    20% {
      border-color: transparent;
      border-left-color: var(--fill-color);
      border-top-color: var(--fill-color);
    }
    30% {
      border-color: transparent;
      border-left-color: var(--fill-color);
      border-top-color: var(--fill-color);
      border-right-color: var(--fill-color);
    }
    40% {
      border-color: transparent;
      border-right-color: var(--fill-color);
      border-top-color: var(--fill-color);
    }
    60% {
      border-color: transparent;
      border-right-color: var(--fill-color);
    }
    80% {
      border-color: transparent;
      border-right-color: var(--fill-color);
      border-bottom-color: var(--fill-color);
    }
    90% {
      border-color: transparent;
      border-bottom-color: var(--fill-color);
    }
  }
</style>

      <script>
        async function quickchart(key) {
          const quickchartButtonEl =
            document.querySelector('#' + key + ' button');
          quickchartButtonEl.disabled = true;  // To prevent multiple clicks.
          quickchartButtonEl.classList.add('colab-df-spinner');
          try {
            const charts = await google.colab.kernel.invokeFunction(
                'suggestCharts', [key], {});
          } catch (error) {
            console.error('Error during call to suggestCharts:', error);
          }
          quickchartButtonEl.classList.remove('colab-df-spinner');
          quickchartButtonEl.classList.add('colab-df-quickchart-complete');
        }
        (() => {
          let quickchartButtonEl =
            document.querySelector('#df-847b3c03-77d4-4550-9c47-0d1e7e39ce17 button');
          quickchartButtonEl.style.display =
            google.colab.kernel.accessAllowed ? 'block' : 'none';
        })();
      </script>
    </div>

  <div id="id_f671b0e5-5b49-4ebe-b1b7-41fa1f0f1c0c">
    <style>
      .colab-df-generate {
        background-color: #E8F0FE;
        border: none;
        border-radius: 50%;
        cursor: pointer;
        display: none;
        fill: #1967D2;
        height: 32px;
        padding: 0 0 0 0;
        width: 32px;
      }

      .colab-df-generate:hover {
        background-color: #E2EBFA;
        box-shadow: 0px 1px 2px rgba(60, 64, 67, 0.3), 0px 1px 3px 1px rgba(60, 64, 67, 0.15);
        fill: #174EA6;
      }

      [theme=dark] .colab-df-generate {
        background-color: #3B4455;
        fill: #D2E3FC;
      }

      [theme=dark] .colab-df-generate:hover {
        background-color: #434B5C;
        box-shadow: 0px 1px 3px 1px rgba(0, 0, 0, 0.15);
        filter: drop-shadow(0px 1px 2px rgba(0, 0, 0, 0.3));
        fill: #FFFFFF;
      }
    </style>
    <button class="colab-df-generate" onclick="generateWithVariable('df_sorted')"
            title="Generate code using this dataframe."
            style="display:none;">

  <svg xmlns="http://www.w3.org/2000/svg" height="24px"viewBox="0 0 24 24"
       width="24px">
    <path d="M7,19H8.4L18.45,9,17,7.55,7,17.6ZM5,21V16.75L18.45,3.32a2,2,0,0,1,2.83,0l1.4,1.43a1.91,1.91,0,0,1,.58,1.4,1.91,1.91,0,0,1-.58,1.4L9.25,21ZM18.45,9,17,7.55Zm-12,3A5.31,5.31,0,0,0,4.9,8.1,5.31,5.31,0,0,0,1,6.5,5.31,5.31,0,0,0,4.9,4.9,5.31,5.31,0,0,0,6.5,1,5.31,5.31,0,0,0,8.1,4.9,5.31,5.31,0,0,0,12,6.5,5.46,5.46,0,0,0,6.5,12Z"/>
  </svg>
    </button>
    <script>
      (() => {
      const buttonEl =
        document.querySelector('#id_f671b0e5-5b49-4ebe-b1b7-41fa1f0f1c0c button.colab-df-generate');
      buttonEl.style.display =
        google.colab.kernel.accessAllowed ? 'block' : 'none';

      buttonEl.onclick = () => {
        google.colab.notebook.generateWithVariable('df_sorted');
      }
      })();
    </script>
  </div>

    </div>
  </div>


<p>ここで使った操作の多くは、この記事の 「最初に覚えたい10個の基本操作」 に含まれています。 分からないところがあれば、該当する項目に戻ったり、リンク先の詳しい解説記事も参照してみてください。</p>

<h2><span id="toc23">実務で最初に覚えるべき DataFrame 操作10個（完全チェックリスト）</span></h2>

<p>DataFrame を使う仕事（データ前処理・分析）では、まず次の 10 個を覚えるだけで 80% のタスクはこなせます。</p>

<ol>
  <li><strong>df.head()</strong>：データの先頭を確認</li>
  <li><strong>df.tail()</strong>：データの末尾を確認</li>
  <li><strong>df.info()</strong>：データ型・欠損の有無を確認</li>
  <li><strong>df.describe(include=&#8217;all&#8217;)</strong>：統計量の確認</li>
  <li><strong>df.columns / df.index</strong>：列名・行名を確認</li>
  <li><strong>df[&#8216;col&#8217;] / df[[&#8216;col&#8217;]]</strong>：列の抽出（Series / DataFrame）</li>
  <li><strong>df.loc[row, col] / df.iloc[row, col]</strong>：行・列の抽出</li>
  <li><strong>df.sort_values()</strong>：並び替え（昇順・降順）</li>
  <li><strong>df.isnull().sum()</strong>：欠損値のチェック</li>
  <li><strong>df.drop()</strong>：列削除・行削除</li>
</ol>

<p>この 10 個を使いこなせるようになると、次のステップ（<code>groupby</code>、<code>merge</code>、<code>concat</code>、<code>pivot_table</code>）が格段に理解しやすくなります。</p>

<div style="padding:1em; background:#f5faff; border-left:4px solid #1976d2; margin-top:1.5em;">
<strong>💡 ワンポイント：</strong><br>
実務では「まず状況把握（head / info / describe）」→「基礎操作（抽出・並べ替え）」→「整形（drop / fillna）」の順で手を動かすと効率が良いです。
</div>


<h2><span id="toc24">✅ まとめ：DataFrameはPandas学習の「土台」</span></h2>
<p>本記事では、pandas dataframe の基本構造・作り方・Seriesとの違い・[] と [[]] の使い分け、最初に押さえておきたい基本操作までを整理しました。</p>

<ul>
<li>DataFrameは「ラベル付きの2次元表」であり、Pandas学習の中心</li>
<li>行・列・インデックス・データ型のイメージを持つことが重要</li>
<li>最初は10個の基本操作だけ押さえればOK（あとは必要に応じて深堀り）</li>
</ul>
<p>DataFrame のイメージが持てるようになれば、あとは loc/iloc・条件抽出・欠損値処理・groupby・merge/concat などを少しずつ練習していくだけです。 次の「関連記事」から、興味のあるものを選んで進んでみてください。</p>

<h2><span id="toc25">関連記事：Pandasデータ分析の次のステップ</span></h2>
<ul>
<p>【Pandas】</p>
<li><a href="https://pythondatalab.com/pandas-head/">head()/tail()で先頭・末尾を確認する</a></li>
<li><a href="https://pythondatalab.com/pandas-info-describe/">info()/describe()で構造と統計量を確認する</a></li>
<li><a href="https://pythondatalab.com/pandas-loc/">locでラベル指定の行・列を抽出する</a></li>
<li><a href="https://pythondatalab.com/pandas-iloc/">ilocで番号指定の行・列を抽出する</a></li>
<li><a href="https://pythondatalab.com/pandas-loc-iloc/">locとilocの違い・使い分け</a></li>
<li><a href="https://pythondatalab.com/pandas-filtering/">条件抽出・フィルタリングの基本</a></li>
<li><a href="https://pythondatalab.com/pandas-sort/">sortで並び替えをする</a></li>
<li><a href="https://pythondatalab.com/pandas-concat/">concatでDataFrameを連結する</a></li>
<li><a href="https://pythondatalab.com/pandas-merge/">mergeでDataFrameを結合する</a></li>
<li><a href="https://pythondatalab.com/pandas-isin/">isinで複数条件をまとめて抽出する</a></li>
<li><a href="https://pythondatalab.com/pandas-isnull/">欠損値を見つける</a></li>
<li><a href="https://pythondatalab.com/pandas-drop/">drop/dropna/drop_duplicatesで行・列・欠損・重複を削除する</a></li>
<li><a href="https://pythondatalab.com/pandas-groupby-agg/">groupby/aggでグループごとに集計する</a></li>
<li><a href="https://pythondatalab.com/pandas-multiindex/">Multiindexで階層型インデックスを作成・集計する</a></li>
<li><a href="https://pythondatalab.com/pandas-pivot/">pivot tableで集計する</a></li>
</ul>
<ul>
<p>【Matplotlib】</p>
<li><a href="https://pythondatalab.com/category/pandas/visualization/">▶ MatplotlibでPandasデータを可視化する方法</a></li>
</ul>
<h2><span id="toc26">Zenn・Qiitaでも要点まとめています</span></h2>
<p>記事の要点だけをサクッと復習したい場合は、Zenn・Qiita にまとめたショート版もどうぞ。</p>
<ul>
<li><a rel="noopener" href="https://zenn.dev/coin_collector/articles/a262462b739a64" target="_blank">Zenn：Pandas DataFrame入門の要点まとめ</a></li>
<li><a rel="noopener" href="https://qiita.com/coin_collector/items/1ed795afdd7310ba42d6" target="_blank">Qiita：Pandas DataFrame入門の要点まとめ</a></li>
</ul>
</div>


 

  <p style="text-align: center; margin-top: 2em;">
    <a href="#top">▲ ページトップへ戻る</a>
  </p>


<div id="rank-math-faq" class="rank-math-block">
<div class="rank-math-list ">
<div id="faq-question-1764004097522" class="rank-math-list-item">
<h3 class="rank-math-question "><span id="toc27">Q1. DataFrame と Excel の表は何が違いますか？</span></h3>
<div class="rank-math-answer ">

<p>見た目は似ていますが、 DataFrameはプログラムから自由に操作できる表 です。 列ごとのデータ型を意識しながら、条件抽出・集計・結合・可視化などをコードで再現できます。 一度書いた処理は、別のデータセットにも簡単に再利用できる点が大きな違いです。</p>

</div>
</div>
<div id="faq-question-1764004120878" class="rank-math-list-item">
<h3 class="rank-math-question "><span id="toc28">Q2. DataFrame を作ったあと、まず何を確認すればいいですか？</span></h3>
<div class="rank-math-answer ">

<p>次の 4 つをセットで確認するのがおすすめです。<br />df.shape – 行数と列数<br />df.columns – 列名<br />df.dtypes – 各列のデータ型<br />df.head() – 先頭数行<br />これらを見ておくことで、「どんなデータがどれくらいあるのか」「文字列だと思っていた列が実は数値として扱われている」などの気づきを早期に得られます。 <a href="https://pythondatalab.com/pandas-head/">head()/tail()の使い方まとめ</a> も併せてどうぞ。</p>

</div>
</div>
<div id="faq-question-1764004134985" class="rank-math-list-item">
<h3 class="rank-math-question "><span id="toc29">Q3. DataFrameの行・列の抽出はどこで学べばいいですか？</span></h3>
<div class="rank-math-answer ">

<p>行・列の抽出には loc （ラベルベース）と iloc （番号ベース）がよく使われます。 それぞれの基本的な使い方と、違い・使い分けは次の記事で詳しく解説しています。<br />▶<a href="https://pythondatalab.com/pandas-loc/">locでラベル抽出</a><br />▶<a href="https://pythondatalab.com/pandas-iloc/">ilocで番号抽出</a><br />▶<a href="https://pythondatalab.com/pandas-loc-iloc/">locとilocの違い・使い分け</a></p>

</div>
</div>
<div id="faq-question-1764004161510" class="rank-math-list-item">
<h3 class="rank-math-question "><span id="toc30">Q4. 列名を変更したいときはどうすればいいですか？</span></h3>
<div class="rank-math-answer ">

<p>列名の変更には rename() を使います。<br />df_renamed = df.rename(columns={&#8216;Name&#8217;: &#8216;name&#8217;, &#8216;Age&#8217;: &#8216;age&#8217;})<br />元のDataFrameを直接書き換えたい場合は、 inplace=True を指定するか、上書き代入（ df = df.rename(…) ）を行います。</p>

</div>
</div>
<div id="faq-question-1764004180768" class="rank-math-list-item">
<h3 class="rank-math-question "><span id="toc31">Q5. 数値の列が object 型（文字列）になってしまいました…</span></h3>
<div class="rank-math-answer ">

<p>CSV読み込み時などに、数値の列が object 型になってしまうことがあります。 その場合は、 astype() や pd.to_numeric() で型変換します。<br /> <br /># &#8216;Age&#8217; 列を数値型に変換（変換できない値は NaN にする例）<br />df[&#8216;Age&#8217;] = pd.to_numeric(df[&#8216;Age&#8217;], errors=&#8217;coerce&#8217;)<br />display(df.dtypes)</p>
<p>変換時にエラーが出る場合は、空文字や「-」など数値に変換できない値が混ざっていることが多いです。 pd.to_numeric(df[&#8216;Age&#8217;], errors=&#8217;coerce&#8217;) でいったん NaN にし、その後 fillna や dropna で処理するのが定番パターンです。</p>

</div>
</div>
<div id="faq-question-1764004193895" class="rank-math-list-item">
<h3 class="rank-math-question "><span id="toc32">Q6. DataFrameをExcelやCSVに保存するには？</span></h3>
<div class="rank-math-answer ">

<p>DataFrameは to_csv() や to_excel() で簡単に保存できます。</p>
<p># CSVとして保存（インデックスは保存しない例）<br />df.to_csv(&#8216;output.csv&#8217;, index=False)</p>
<p># Excelとして保存<br />df.to_excel(&#8216;output.xlsx&#8217;, index=False)</p>
<p>Google Colab と Google Drive を組み合わせてファイルを読み書きする方法は、次の記事で詳しく解説しています。<br /> ▶ <a href="https://pythondatalab.com/google-colab-csv/">Google Colab CSV 読み込み＆保存入門</a></p>

</div>
</div>
<div id="faq-question-1764004207959" class="rank-math-list-item">
<h3 class="rank-math-question "><span id="toc33">Q7. DataFrameの処理が遅いときはどうすればいいですか？</span></h3>
<div class="rank-math-answer ">

<p>for文で1行ずつ処理していると、Python側のループがボトルネックになります。 可能な限り 「列全体に対する演算（ベクトル化）」 や、 apply / map などの関数を使うと高速化しやすくなります。 どうしても重い場合は、行数・列数が大きすぎないか（ df.shape ）も確認しましょう。</p>

</div>
</div>
<div id="faq-question-1764004227758" class="rank-math-list-item">
<h3 class="rank-math-question "><span id="toc34">Q8. DataFrameをコピーするときに注意することは？</span></h3>
<div class="rank-math-answer ">

<p>df2 = df のように代入すると、 同じオブジェクトを指す別名 になります。 別の独立したDataFrameがほしい場合は、 df.copy() を使いましょう。<br /> <br />df2 = df.copy() # これで独立したコピーになる</p>

</div>
</div>
</div>
</div>


<p class="wp-block-paragraph"></p>
<p>&lt;p&gt;The post <a rel="nofollow" href="https://pythondatalab.com/pandas-dataframe/">Pandas DataFrame入門｜作り方と基本操作を初心者向けに解説</a> first appeared on <a rel="nofollow" href="https://pythondatalab.com">Python Data Lab（Pythonデータラボ）</a>.&lt;/p&gt;</p>
]]></content:encoded>
					
					<wfw:commentRss>https://pythondatalab.com/pandas-dataframe/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Google ColabでCSVを読み込む方法｜Drive連携とpandas read_csvを初心者向けに解説</title>
		<link>https://pythondatalab.com/google-colab-csv/</link>
					<comments>https://pythondatalab.com/google-colab-csv/#respond</comments>
		
		<dc:creator><![CDATA[coin_collector]]></dc:creator>
		<pubDate>Sun, 23 Mar 2025 14:56:18 +0000</pubDate>
				<category><![CDATA[基礎]]></category>
		<guid isPermaLink="false">https://pythondatalab.com/?p=522</guid>

					<description><![CDATA[<p>Google ColabでCSVを読み込む方法を初心者向けに解説。Google Driveのマウント、ファイルパス確認、pandas read_csvでのCSV読み込み、読み込めないときの対処法、CSV保存までわかりやすく説明します。</p>
<p>&lt;p&gt;The post <a rel="nofollow" href="https://pythondatalab.com/google-colab-csv/">Google ColabでCSVを読み込む方法｜Drive連携とpandas read_csvを初心者向けに解説</a> first appeared on <a rel="nofollow" href="https://pythondatalab.com">Python Data Lab（Pythonデータラボ）</a>.&lt;/p&gt;</p>
]]></description>
										<content:encoded><![CDATA[
<!-- WordPress カスタムHTMLブロック貼り付け用：Google Colab CSV 読み込み記事 読みやすさ改善版 -->
<div id="top" class="colab-article">

<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/prismjs/themes/prism-tomorrow.min.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/prismjs/plugins/toolbar/prism-toolbar.min.css">
<script src="https://cdn.jsdelivr.net/npm/prismjs/components/prism-core.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/prismjs/components/prism-clike.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/prismjs/components/prism-python.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/prismjs/plugins/toolbar/prism-toolbar.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/prismjs/plugins/copy-to-clipboard/prism-copy-to-clipboard.min.js"></script>

<style>
  .colab-article {
    line-height: 1.85;
    font-size: 16px;
  }
  .colab-article p {
    margin: 0.7em 0;
  }
  .colab-article h2 {
    margin-top: 2.2em;
    margin-bottom: 0.8em;
    padding-bottom: 0.35em;
    border-bottom: 2px solid #e0f2f1;
    line-height: 1.45;
  }
  .colab-article h3 {
    margin-top: 1.8em;
    margin-bottom: 0.6em;
    line-height: 1.45;
  }
  .colab-article pre[class*="language-"] {
    margin: 0.9em 0 1.3em 0 !important;
    padding: 1em;
    border-radius: 8px;
    overflow-x: auto;
  }
  .colab-article code {
    font-family: Consolas, Monaco, "Courier New", monospace;
  }
  .colab-article .lead-box,
  .colab-article .point-box,
  .colab-article .note-box,
  .colab-article .warning-box,
  .colab-article .answer-box {
    border-radius: 10px;
    padding: 1em 1.2em;
    margin: 1.2em 0;
  }
  .colab-article .lead-box {
    border: 2px solid #4db6ac;
    background: #f0fdfa;
  }
  .colab-article .point-box {
    border: 2px solid #4db6ac;
    background: #f0fdfa;
  }
  .colab-article .answer-box {
    border-left: 5px solid #00897b;
    background: #f4fffd;
  }
  .colab-article .note-box {
    border-left: 5px solid #0073aa;
    background: #f8faff;
  }
  .colab-article .warning-box {
    border-left: 5px solid #e67e22;
    background: #fff8ee;
  }
  .colab-article .mini-title {
    font-weight: 700;
    margin-bottom: 0.4em;
  }
  .colab-article .toc-box {
    border: 1px solid #d9ecea;
    background: #fbfffe;
    border-radius: 10px;
    padding: 1em 1.2em;
    margin: 1.4em 0;
  }
  .colab-article .toc-box ul {
    margin: 0.4em 0 0 1.2em;
    padding: 0;
  }
  .colab-article .toc-box li {
    margin: 0.25em 0;
  }
  .colab-article .step-summary {
    display: grid;
    grid-template-columns: 1fr;
    gap: 0.75em;
    margin: 1em 0;
  }
  .colab-article .step-card {
    border: 1px solid #d9ecea;
    background: #ffffff;
    border-radius: 10px;
    padding: 0.8em 1em;
  }
  .colab-article .step-card strong {
    color: #00695c;
  }
  .colab-article table.wp-block-table {
    width: auto;
    max-width: 100%;
    border-collapse: collapse;
    margin: 0.9em 0 1.3em 0;
    overflow-x: auto;
    display: block;
  }
  .colab-article table.wp-block-table th,
  .colab-article table.wp-block-table td {
    padding: 0.35em 0.6em;
    white-space: nowrap;
    border: 1px solid #ddd;
  }
  .colab-article table.wp-block-table th {
    background: #f7f7f7;
  }
  .colab-article table.wp-block-table td:first-child,
  .colab-article table.wp-block-table th:first-child {
    min-width: 3em;
  }
  .colab-article figure {
    margin: 1.2em 0;
  }
  .colab-article figure img {
    max-width: 100%;
    height: auto;
    border: 1px solid #ddd;
    border-radius: 6px;
  }
  .colab-article figcaption {
    font-size: 0.9em;
    color: #666;
    margin-top: 0.4em;
  }
  .colab-article .series-nav {
    border: 2px solid #4db6ac;
    background: linear-gradient(135deg, #f0fdfa 0%, #e0f7f4 100%);
    padding: 14px 18px;
    border-radius: 10px;
    margin: 1.5em 0;
    box-shadow: 0 3px 6px rgba(0,0,0,0.05);
  }
  .colab-article .related-box {
    border: 2px solid #0073aa;
    border-radius: 10px;
    padding: 1em 1.2em;
    margin-top: 2em;
    background: #f8faff;
  }
  .colab-article .related-box h3 {
    margin-top: 0;
    color: #0073aa;
  }
  .colab-article .related-box ul {
    list-style-type: none;
    margin: 0;
    padding: 0;
  }
  .colab-article .related-box li {
    margin: 0.45em 0;
  }
</style>

<div class="lead-box">
  <p><strong>Google ColabでCSVを読み込むには、Google Driveを接続して、pandasの<code>read_csv()</code>を使います。</strong></p>
  <p>この記事では、CSVをGoogle Driveに置くところから、Colabで読み込み、読み込んだデータを確認し、必要に応じてCSVとして保存するところまでを、初心者向けに順番に解説します。</p>
</div>

<div class="answer-box">
  <p class="mini-title">まずは結論：最短コード</p>
  <p>Google Driveのマイドライブ直下に<code>height_weight.csv</code>を置いている場合は、次のコードで読み込めます。</p>
</div>

<pre class="language-python" data-prismjs-copy="コピー"><code class="language-python">from google.colab import drive
drive.mount('/content/drive')

import pandas as pd

df = pd.read_csv('/content/drive/MyDrive/height_weight.csv')
df.head()</code></pre>

<div class="note-box">
  <p><strong>ポイント：</strong><code>/content/drive/MyDrive/height_weight.csv</code>の部分は、自分のCSVファイルの保存場所に合わせて変更してください。</p>
</div>

<div class="toc-box">
  <p class="mini-title">この記事の流れ</p>
  <ul>
    <li><a href="#overview">Google ColabでCSVを読み込む全体像</a></li>
    <li><a href="#upload">ステップ1：CSVをGoogle Driveにアップロードする</a></li>
    <li><a href="#mount">ステップ2：Google Driveをマウントする</a></li>
    <li><a href="#path">ステップ3：CSVファイルのパスを確認する</a></li>
    <li><a href="#readcsv">ステップ4：read_csv()でCSVを読み込む</a></li>
    <li><a href="#check">ステップ5：読み込んだデータを確認する</a></li>
    <li><a href="#trouble">CSVが読み込めないときの対処法</a></li>
    <li><a href="#save">CSVとしてGoogle Driveに保存する</a></li>
  </ul>
</div>

<!-- ▼▼▼ Pandasシリーズナビ（開始） ▼▼▼ -->
<div id="pandas-series-nav" class="series-nav">
  <p style="margin: 0 0 6px 0; font-weight: 600; color: #00695c; font-size: 1.05em;">💡 Pandas DataFrame入門シリーズ</p>
  <p style="margin: 0; line-height: 1.7; color: #333;">
    このページは「<a style="color: #00796b; text-decoration: underline; font-weight: 500;" href="https://pythondatalab.com/pandas-dataframe/">Pandas DataFrame入門</a>」シリーズの一部です。<br>
    データの作成から結合・集計までを体系的に学べます。
  </p>
</div>
<!-- ▲▲▲ Pandasシリーズナビ（終了） ▲▲▲ -->


  <div id="toc" class="toc tnt-number toc-center tnt-number border-element"><input type="checkbox" class="toc-checkbox" id="toc-checkbox-6" checked><label class="toc-title" for="toc-checkbox-6">目次</label>
    <div class="toc-content">
    <ol class="toc-list open"><li><a href="#toc1" tabindex="0">この記事でわかること</a></li><li><a href="#toc2" tabindex="0">Google ColabでCSVを読み込む全体像</a></li><li><a href="#toc3" tabindex="0">ステップ1｜CSVファイルをGoogle Driveにアップロードする</a></li><li><a href="#toc4" tabindex="0">ステップ2｜Google ColabでGoogle Driveをマウントする</a><ol><li><a href="#toc5" tabindex="0">Driveが接続できたか確認する</a></li></ol></li><li><a href="#toc6" tabindex="0">ステップ3｜CSVファイルのパスを確認する</a><ol><li><a href="#toc7" tabindex="0">ファイルパスは「パスをコピー」で確認する</a></li></ol></li><li><a href="#toc8" tabindex="0">ステップ4｜pandasのread_csv()でCSVを読み込む</a></li><li><a href="#toc9" tabindex="0">ステップ5｜読み込んだCSVを確認する</a><ol><li><a href="#toc10" tabindex="0">info()で列名・データ型・欠損値を確認する</a></li><li><a href="#toc11" tabindex="0">describe()で数値データの統計量を確認する</a></li></ol></li><li><a href="#toc12" tabindex="0">Google ColabでCSVが読み込めないときの対処法</a><ol><li><a href="#toc13" tabindex="0">FileNotFoundError：ファイルが見つからない</a></li><li><a href="#toc14" tabindex="0">文字化けする場合：encodingを指定する</a></li><li><a href="#toc15" tabindex="0">列がうまく分かれない場合：sepを指定する</a></li><li><a href="#toc16" tabindex="0">ヘッダー行がずれる場合：headerを指定する</a></li></ol></li><li><a href="#toc17" tabindex="0">読み込んだデータをCSVとしてGoogle Driveに保存する</a></li><li><a href="#toc18" tabindex="0">Excelファイルを読み込みたい場合</a></li><li><a href="#toc19" tabindex="0">まとめ：Google ColabでCSVを読み込む基本はDrive接続とread_csv()</a><ol><li><a href="#toc20" tabindex="0">関連記事：次に読むと理解が深まる記事</a></li><li><a href="#toc21" tabindex="0">Google Colabでは毎回Google Driveをマウントする必要がありますか？</a></li><li><a href="#toc22" tabindex="0">CSVファイルはGoogle Driveのどこに置けばよいですか？</a></li><li><a href="#toc23" tabindex="0">read_csv()で読み込んだデータはどこに入りますか？</a></li><li><a href="#toc24" tabindex="0">CSV保存時のindex=Falseは必要ですか？</a></li></ol></li></ol>
    </div>
  </div>

<h2><span id="toc1">この記事でわかること</span></h2>

<ul>
  <li>Google Driveに保存したCSVをGoogle Colabで読み込む方法</li>
  <li>Google ColabでGoogle Driveをマウントする方法</li>
  <li>CSVファイルのパスを確認する方法</li>
  <li>pandasの<code>read_csv()</code>でCSVを読み込む方法</li>
  <li>CSVが読み込めないときの主な原因と対処法</li>
  <li>読み込んだDataFrameをCSVとしてGoogle Driveに保存する方法</li>
</ul>

<p>Pythonの実行環境で迷っている方は、先にこちらの記事も参考にしてください。</p>
<p><a href="https://pythondatalab.com/python-install/">【初心者向け】Pythonの実行環境を比較！Colab・Anaconda・インストールの違いと使い方</a></p>

<h2 id="overview"><span id="toc2">Google ColabでCSVを読み込む全体像</span></h2>

<p>Google Colabは、ブラウザ上でPythonを実行できる便利な環境です。ただし、Google Driveに保存したCSVを読み込むには、まずColabからDriveにアクセスできる状態にする必要があります。</p>

<p>基本の流れは、次の5つです。</p>

<div class="step-summary">
  <div class="step-card"><strong>1. CSVをGoogle Driveに置く</strong><br>読み込みたいCSVファイルを、Google Driveにアップロードします。</div>
  <div class="step-card"><strong>2. DriveをColabに接続する</strong><br><code>drive.mount('/content/drive')</code>で、ColabからDriveを使えるようにします。</div>
  <div class="step-card"><strong>3. CSVのパスを確認する</strong><br>Colabのファイル一覧から「パスをコピー」すると安全です。</div>
  <div class="step-card"><strong>4. CSVを読み込む</strong><br><code>pd.read_csv()</code>でCSVをDataFrameとして読み込みます。</div>
  <div class="step-card"><strong>5. 必要に応じて保存する</strong><br><code>df.to_csv()</code>で、処理結果をCSVとして保存できます。</div>
</div>


<h2 id="upload"><span id="toc3">ステップ1｜CSVファイルをGoogle Driveにアップロードする</span></h2>

<p>まず、読み込みたいCSVファイルをGoogle Driveに保存します。</p>

<p>この記事では、例としてマイドライブ直下に<code>height_weight.csv</code>というファイルを置いた前提で進めます。自分のCSVを使う場合は、ファイル名を読み替えてください。</p>

<figure>
  <img src="https://pythondatalab.com/wp-content/uploads/2025/06/google_drive_mydrive.jpg" alt="Google DriveのマイドライブにCSVファイルを保存した画面" width="800" height="500" loading="lazy" decoding="async">
  <figcaption>図：Google DriveのマイドライブにCSVファイルを保存した例</figcaption>
</figure>

<div class="warning-box">
  <p><strong>注意：</strong>ファイル名は、大文字・小文字、拡張子の<code>.csv</code>、スペースの有無まで一致させる必要があります。</p>
</div>

<h2 id="mount"><span id="toc4">ステップ2｜Google ColabでGoogle Driveをマウントする</span></h2>

<p>次に、Google ColabからGoogle Driveにアクセスできるようにします。この接続作業を「マウント」といいます。</p>

<p>Colabのコードセルに、次のコードを入力して実行してください。</p>

<pre class="language-python" data-prismjs-copy="コピー"><code class="language-python">from google.colab import drive
drive.mount('/content/drive')</code></pre>

<figure>
  <img src="https://pythondatalab.com/wp-content/uploads/2025/06/drive_mount.png" alt="Google Colabでdrive.mount()を実行してGoogle Driveを接続する画面" width="800" height="500" loading="lazy" decoding="async">
  <figcaption>図：Google Colabで<code>drive.mount()</code>を実行する画面</figcaption>
</figure>

<p>実行すると、Google Driveへの接続を許可する画面が表示されます。「Googleドライブに接続」をクリックし、画面の指示に従って進めます。</p>

<figure>
  <img src="https://pythondatalab.com/wp-content/uploads/2025/03/drive_mount2.png" alt="Google ColabでGoogle Driveへのアクセスを許可する画面" width="800" height="500" loading="lazy" decoding="async">
  <figcaption>図：Google Driveへのアクセスを許可する画面</figcaption>
</figure>

<p>認証が完了すると、<code>Mounted at /content/drive</code>のようなメッセージが表示されます。これで、ColabからGoogle Drive内のファイルにアクセスできます。</p>

<h3><span id="toc5">Driveが接続できたか確認する</span></h3>

<p>Colab画面の左側にあるフォルダアイコンをクリックします。ファイル一覧に<code>drive</code>フォルダが表示されていれば成功です。</p>

<figure>
  <img src="https://pythondatalab.com/wp-content/uploads/2025/03/drive_mount3-1.png" alt="Google Colabのファイル一覧にdriveフォルダが表示されている画面" width="800" height="500" loading="lazy" decoding="async">
  <figcaption>図：ファイル一覧に<code>drive</code>フォルダが表示された状態</figcaption>
</figure>

<h2 id="path"><span id="toc6">ステップ3｜CSVファイルのパスを確認する</span></h2>

<p>CSVを読み込むには、「どこにあるCSVファイルを読み込むのか」をColabに教える必要があります。この場所を表す文字列がファイルパスです。</p>

<p>Google Driveをマウントした場合、マイドライブは通常、次の場所から始まります。</p>

<pre class="language-python" data-prismjs-copy="コピー"><code class="language-python">/content/drive/MyDrive/</code></pre>

<p>例えば、マイドライブ直下に<code>height_weight.csv</code>を保存している場合、ファイルパスは次のようになります。</p>

<pre class="language-python" data-prismjs-copy="コピー"><code class="language-python">/content/drive/MyDrive/height_weight.csv</code></pre>

<h3><span id="toc7">ファイルパスは「パスをコピー」で確認する</span></h3>

<p>手入力すると、ファイル名やフォルダ名を間違えやすくなります。初心者の方は、Colabのファイル一覧からパスをコピーする方法がおすすめです。</p>

<ol>
  <li>Colab左側のフォルダアイコンをクリックする</li>
  <li><code>drive</code> → <code>MyDrive</code>を開く</li>
  <li>読み込みたいCSVファイルを右クリックする</li>
  <li>「パスをコピー」をクリックする</li>
</ol>

<div class="note-box">
  <p><strong>よくある失敗：</strong><code>FileNotFoundError</code>の多くは、ファイルパスの入力ミスが原因です。迷ったら、手入力ではなく「パスをコピー」を使いましょう。</p>
</div>

<h2 id="readcsv"><span id="toc8">ステップ4｜pandasのread_csv()でCSVを読み込む</span></h2>

<p>ファイルパスを確認できたら、pandasの<code>read_csv()</code>でCSVを読み込みます。</p>

<p>まず、pandasを使えるようにします。</p>

<pre class="language-python" data-prismjs-copy="コピー"><code class="language-python">import pandas as pd</code></pre>

<p>次に、CSVファイルを読み込みます。</p>

<pre class="language-python" data-prismjs-copy="コピー"><code class="language-python">df = pd.read_csv('/content/drive/MyDrive/height_weight.csv')</code></pre>

<p>このコードは、指定した場所にあるCSVファイルを読み込み、<code>df</code>という名前のDataFrameとして扱えるようにする、という意味です。</p>

<div class="note-box">
  <p><strong>DataFrameとは：</strong>pandasで扱う表形式データのことです。Excelの表のように、行と列でデータを管理できます。</p>
</div>

<p>pandasの<code>read_csv()</code>の詳しい仕様は、公式ドキュメントでも確認できます。</p>
<p><a rel="noopener" href="https://pandas.pydata.org/docs/reference/api/pandas.read_csv.html" target="_blank">pandas read_csv 公式ドキュメント</a></p>

<h2 id="check"><span id="toc9">ステップ5｜読み込んだCSVを確認する</span></h2>

<p>CSVを読み込んだら、まず<code>df.head()</code>で先頭の数行を確認します。</p>

<pre class="language-python" data-prismjs-copy="コピー"><code class="language-python">df.head()</code></pre>

<table class="wp-block-table">
  <thead>
    <tr>
      <th></th>
      <th>Name</th>
      <th>Height(cm)</th>
      <th>Weight(kg)</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>0</th>
      <td>NQjXU</td>
      <td>152</td>
      <td>53</td>
    </tr>
    <tr>
      <th>1</th>
      <td>rcXej</td>
      <td>165</td>
      <td>51</td>
    </tr>
    <tr>
      <th>2</th>
      <td>FMtIp</td>
      <td>188</td>
      <td>56</td>
    </tr>
    <tr>
      <th>3</th>
      <td>gymZI</td>
      <td>183</td>
      <td>64</td>
    </tr>
    <tr>
      <th>4</th>
      <td>BqzCl</td>
      <td>150</td>
      <td>81</td>
    </tr>
  </tbody>
</table>

<p>このように表の先頭行が表示されれば、CSVファイルの読み込みは成功です。</p>

<p><code>head()</code>の詳しい使い方は、こちらの記事で解説しています。</p>
<p><a href="https://pythondatalab.com/pandas-head/">【初心者向け】Pandasのhead関数の使い方とDataFrameの先頭行を表示する具体的手順を解説</a></p>

<h3><span id="toc10">info()で列名・データ型・欠損値を確認する</span></h3>

<p>CSVが読み込めたら、<code>info()</code>で列名、データ型、欠損値の有無を確認できます。</p>

<pre class="language-python" data-prismjs-copy="コピー"><code class="language-python">df.info()</code></pre>

<figure>
  <img src="https://pythondatalab.com/wp-content/uploads/2025/05/df.info_.png" alt="pandasのdf.info()で列名やデータ型を確認した結果" width="800" height="500" loading="lazy" decoding="async">
  <figcaption>図：<code>df.info()</code>の表示結果</figcaption>
</figure>

<h3><span id="toc11">describe()で数値データの統計量を確認する</span></h3>

<p>数値列の平均値、標準偏差、最小値、最大値などを確認したい場合は、<code>describe()</code>を使います。</p>

<pre class="language-python" data-prismjs-copy="コピー"><code class="language-python">df.describe()</code></pre>

<table class="wp-block-table">
  <thead>
    <tr>
      <th></th>
      <th>Height(cm)</th>
      <th>Weight(kg)</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>count</th>
      <td>100.000000</td>
      <td>100.000000</td>
    </tr>
    <tr>
      <th>mean</th>
      <td>173.110000</td>
      <td>70.960000</td>
    </tr>
    <tr>
      <th>std</th>
      <td>16.084936</td>
      <td>16.403941</td>
    </tr>
    <tr>
      <th>min</th>
      <td>150.000000</td>
      <td>45.000000</td>
    </tr>
    <tr>
      <th>25%</th>
      <td>160.000000</td>
      <td>58.000000</td>
    </tr>
    <tr>
      <th>50%</th>
      <td>171.500000</td>
      <td>69.000000</td>
    </tr>
    <tr>
      <th>75%</th>
      <td>188.000000</td>
      <td>85.250000</td>
    </tr>
    <tr>
      <th>max</th>
      <td>200.000000</td>
      <td>100.000000</td>
    </tr>
  </tbody>
</table>

<p><code>info()</code>と<code>describe()</code>の詳しい使い方は、こちらの記事で解説しています。</p>
<p><a href="https://pythondatalab.com/pandas-info-describe/">【初心者向け】Pandasのinfo()・describe()でデータ構造と統計量をやさしく理解する方法</a></p>

<h2 id="trouble"><span id="toc12">Google ColabでCSVが読み込めないときの対処法</span></h2>

<p>CSVが読み込めないときは、まず次の順番で確認しましょう。</p>

<div class="point-box">
  <ol>
    <li>Google Driveをマウントしたか</li>
    <li>CSVファイルのパスを正しくコピーしたか</li>
    <li>ファイル名と拡張子<code>.csv</code>が合っているか</li>
    <li>日本語が文字化けする場合は<code>encoding</code>を指定したか</li>
    <li>列が分かれない場合は<code>sep</code>を指定したか</li>
  </ol>
</div>

<h3><span id="toc13">FileNotFoundError：ファイルが見つからない</span></h3>

<p><code>FileNotFoundError: [Errno 2] No such file or directory</code>は、指定した場所にファイルが見つからないときに出るエラーです。</p>

<p>主な原因は、ファイルパスの間違いです。次の点を確認してください。</p>

<ul>
  <li>Google Driveをマウントしているか</li>
  <li>ファイル名の大文字・小文字が一致しているか</li>
  <li><code>.csv</code>の拡張子まで正しく書いているか</li>
  <li>フォルダ名やスラッシュ<code>/</code>が間違っていないか</li>
  <li>ファイルが本当にマイドライブ内にあるか</li>
</ul>

<p>対処法としては、CSVファイルを右クリックし、「パスをコピー」を使うのが一番確実です。</p>

<h3><span id="toc14">文字化けする場合：encodingを指定する</span></h3>

<p>日本語が文字化けする場合は、<code>encoding</code>を指定します。</p>

<pre class="language-python" data-prismjs-copy="コピー"><code class="language-python">df = pd.read_csv('/content/drive/MyDrive/height_weight.csv', encoding='utf-8')</code></pre>

<p>日本語Windows環境で作成したCSVの場合は、<code>cp932</code>や<code>shift_jis</code>で読み込めることがあります。</p>

<pre class="language-python" data-prismjs-copy="コピー"><code class="language-python">df = pd.read_csv('/content/drive/MyDrive/height_weight.csv', encoding='cp932')</code></pre>

<h3><span id="toc15">列がうまく分かれない場合：sepを指定する</span></h3>

<p>CSVファイルによっては、カンマではなくタブやセミコロンで区切られていることがあります。その場合は、<code>sep</code>を指定します。</p>

<pre class="language-python" data-prismjs-copy="コピー"><code class="language-python"># タブ区切りの場合
df = pd.read_csv('/content/drive/MyDrive/sample.tsv', sep='\t')

# セミコロン区切りの場合
df = pd.read_csv('/content/drive/MyDrive/sample.csv', sep=';')</code></pre>

<h3><span id="toc16">ヘッダー行がずれる場合：headerを指定する</span></h3>

<p>CSVの1行目が列名ではない場合は、<code>header</code>を指定します。</p>

<pre class="language-python" data-prismjs-copy="コピー"><code class="language-python"># 1行目を列名として扱わない場合
df = pd.read_csv('/content/drive/MyDrive/sample.csv', header=None)</code></pre>

<h2 id="save"><span id="toc17">読み込んだデータをCSVとしてGoogle Driveに保存する</span></h2>

<p>読み込んだデータを加工したあと、CSVとしてGoogle Driveに保存したい場合は、pandasの<code>to_csv()</code>を使います。</p>

<p>例えば、<code>df</code>をマイドライブに<code>height_weight2.csv</code>として保存する場合は、次のように書きます。</p>

<pre class="language-python" data-prismjs-copy="コピー"><code class="language-python">df.to_csv('/content/drive/MyDrive/height_weight2.csv', index=False)</code></pre>

<p><code>index=False</code>を付けると、DataFrameの左端にあるインデックス番号をCSVに保存しないようにできます。通常、CSVとして保存するときは<code>index=False</code>を付けることが多いです。</p>

<div class="warning-box">
  <p><strong>注意：</strong>同じファイル名で保存すると、既存のファイルが上書きされる場合があります。大切なファイルを残したい場合は、別のファイル名で保存しましょう。</p>
</div>

<p>pandasの<code>to_csv()</code>の詳しい仕様は、公式ドキュメントで確認できます。</p>
<p><a rel="noopener" href="https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.to_csv.html" target="_blank">pandas DataFrame.to_csv 公式ドキュメント</a></p>

<h2><span id="toc18">Excelファイルを読み込みたい場合</span></h2>

<p>CSVではなくExcelファイルを読み込みたい場合は、pandasの<code>read_excel()</code>を使います。</p>

<pre class="language-python" data-prismjs-copy="コピー"><code class="language-python">df_excel = pd.read_excel('/content/drive/MyDrive/sample.xlsx')</code></pre>

<p>詳しい使い方は、こちらの記事で解説しています。</p>
<p><a href="https://pythondatalab.com/pandas-read-excel/">pandas read_excelの使い方｜Excelファイルを読み込む方法を初心者向けに解説</a></p>


<h2><span id="toc19">まとめ：Google ColabでCSVを読み込む基本はDrive接続とread_csv()</span></h2>

<p>この記事では、Google ColabでGoogle Drive上のCSVファイルを読み込む方法を解説しました。</p>

<ol>
  <li>CSVファイルをGoogle Driveにアップロードする</li>
  <li><code>drive.mount()</code>でGoogle DriveをColabに接続する</li>
  <li>CSVファイルのパスを確認する</li>
  <li><code>pd.read_csv()</code>でCSVファイルを読み込む</li>
  <li><code>df.head()</code>や<code>df.info()</code>で読み込み結果を確認する</li>
  <li><code>df.to_csv()</code>でCSVとしてGoogle Driveに保存する</li>
</ol>

<p>Google ColabでCSVを扱えるようになると、pandasを使ったデータ分析を進めやすくなります。まずは自分のCSVファイルをGoogle Driveに置き、今回のコードを使って読み込んでみましょう。</p>

<div class="related-box">
  <h3><span id="toc20">関連記事：次に読むと理解が深まる記事</span></h3>
  <ul>
    <li><a href="https://pythondatalab.com/pandas-dataframe/">▶ Pandas DataFrame入門｜表形式データの基本を理解する</a></li>
    <li><a href="https://pythondatalab.com/pandas-head/">▶ Pandasのhead()でDataFrameの先頭行を確認する方法</a></li>
    <li><a href="https://pythondatalab.com/pandas-info-describe/">▶ pandas info()・describe()でデータ構造と統計量を確認する方法</a></li>
    <li><a href="https://pythondatalab.com/pandas-read-excel/">▶ pandas read_excelの使い方｜Excelファイルを読み込む方法</a></li>
    <li><a href="https://pythondatalab.com/category/pandas/preprocessing/">▶ Pandasでデータ抽出・前処理を行う方法</a></li>
  </ul>
</div>

<p style="text-align: center; margin-top: 2em;"><a href="#top">▲ ページトップへ戻る</a></p>

<script>
  if (window.Prism) {
    Prism.highlightAll();
  }
</script>

</div>


<div id="rank-math-faq" class="rank-math-block">
<div class="rank-math-list ">
<div id="faq-question-1780149747919" class="rank-math-list-item">
<h3 class="rank-math-question "><span id="toc21">Google Colabでは毎回Google Driveをマウントする必要がありますか？</span></h3>
<div class="rank-math-answer ">

<p>基本的には、ノートブックを開き直したり、ランタイムを再起動したりした場合は、再度<code>drive.mount('/content/drive')</code>を実行する必要があります。</p>

</div>
</div>
<div id="faq-question-1780149773668" class="rank-math-list-item">
<h3 class="rank-math-question "><span id="toc22">CSVファイルはGoogle Driveのどこに置けばよいですか？</span></h3>
<div class="rank-math-answer ">

<p>初心者の方は、まずマイドライブ直下に置くのがおすすめです。ファイルパスが<code>/content/drive/MyDrive/ファイル名.csv</code>になり、指定しやすいからです</p>

</div>
</div>
<div id="faq-question-1780149794699" class="rank-math-list-item">
<h3 class="rank-math-question "><span id="toc23">read_csv()で読み込んだデータはどこに入りますか？</span></h3>
<div class="rank-math-answer ">

<p><code>df = pd.read_csv(...)</code>と書いた場合、読み込んだCSVデータは<code>df</code>というDataFrameに入ります。以後は、<code>df.head()</code>や<code>df.info()</code>などで中身を確認できます。</p>

</div>
</div>
<div id="faq-question-1780149803157" class="rank-math-list-item">
<h3 class="rank-math-question "><span id="toc24">CSV保存時のindex=Falseは必要ですか？</span></h3>
<div class="rank-math-answer ">

<p>多くの場合は付けた方がよいです。<code>index=False</code>を付けないと、CSVの左端にインデックス番号の列が追加されることがあります。</p>

</div>
</div>
</div>
</div><p>&lt;p&gt;The post <a rel="nofollow" href="https://pythondatalab.com/google-colab-csv/">Google ColabでCSVを読み込む方法｜Drive連携とpandas read_csvを初心者向けに解説</a> first appeared on <a rel="nofollow" href="https://pythondatalab.com">Python Data Lab（Pythonデータラボ）</a>.&lt;/p&gt;</p>
]]></content:encoded>
					
					<wfw:commentRss>https://pythondatalab.com/google-colab-csv/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
