0Pricing
Data Science Academy · レッスン

read_csvと便利なオプション

区切り文字、ヘッダー、インデックス列

「read_csvと便利なオプション」はCoddyKit上の無料Data Science Academyレッスンです。 これはレッスン1/4です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応のAIチューターでハンズオン演習できます。 これはData Science Academy学習パスの一部であり、ウェブとCoddyKitアプリ全体で進捗が同期されます。 Data Science Academyコースには全4レッスンが含まれています。

このレッスンの一部はまだ翻訳されておらず、英語で表示されています。

Data Lives in Files

Real analysis starts with a file on disk. The most common one in data science is the humble CSV: plain text, one row per line. 📄

One Function to Rule Them

pandas reads a CSV with a single call: read_csv. Hand it a path and you get back a ready-to-use DataFrame.

import pandas as pd
df = pd.read_csv("sales.csv")

What Comes Back

read_csv returns a full DataFrame: rows, columns, and an automatic integer index. From here every pandas trick is available to you.

Not Always a Comma

Some files split values with a semicolon or tab instead. The sep option tells pandas exactly which character separates your columns.

df = pd.read_csv("data.csv", sep=";")

When There Is No Header

If the first line is data, not column names, pass header=None so pandas does not steal a real row to use as labels.

df = pd.read_csv("raw.csv", header=None)

Name Your Columns

Pair header=None with names to supply your own column labels in one clean step. Now every column reads clearly.

df = pd.read_csv("raw.csv", header=None,
  names=["date", "item", "price"])

Pick the Index Column

The index_col option promotes a column to be the row index, so lookups by that key feel natural later on.

df = pd.read_csv("sales.csv", index_col="order_id")

Read Only What You Need

Huge file? The usecols option loads just the columns you list, saving memory and keeping your table focused.

df = pd.read_csv("big.csv",
  usecols=["date", "amount"])

Peek With nrows

Not sure a file is clean? Use nrows to read a small sample first, inspect it, then load the rest with confidence.

sample = pd.read_csv("big.csv", nrows=5)

Decode Properly

Strange symbols in your text usually mean the wrong encoding. Setting it to utf-8 fixes most accented and non-English characters. ✅

df = pd.read_csv("names.csv", encoding="utf-8")

Mark Missing as Missing

Files use odd tokens for blanks like NA or n/a. The na_values option turns those into real missing values pandas understands.

df = pd.read_csv("data.csv",
  na_values=["NA", "n/a", "-"])

Quick Check

Your CSV uses semicolons between values. Which option fixes the parse?

Recap: read_csv Mastered

You can now load any CSV: choose the separator, set headers and names, pick the index, trim columns, and flag missing values. 🎉

よくある質問

「read_csvと便利なオプション」レッスンは無料ですか?

はい。「read_csvと便利なオプション」の完全なテキストはこのウェブで無料で読めます。インタラクティブに演習し(組み込みコードエディタと24時間対応のAIチューター)、Data Science Academyコースの残りをアンロックするには、CoddyKit PROにアップグレードしてください。 Data Science Academyコースには全4レッスンが含まれています。

「read_csvと便利なオプション」で何を学びますか?

区切り文字、ヘッダー、インデックス列 ブラウザで直接実行するハンズオンコードでData Science Academyを演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。

Data Science Academyを始めるのに経験は必要ですか?

事前経験は必要ありません。CoddyKitのData Science Academyは初級者から上級者向けに構成されているため、ここから始めるか最初から始めて、自分のペースで進むことができます。 これはレッスン1/4です。

「read_csvと便利なオプション」レッスンにはどのくらい時間がかかりますか?

ほとんどのCoddyKitレッスンは約5~10分かかります。各レッスンはコンパクトでインタラクティブなので、着実に進歩し、ウェブとアプリ全体で正確に前回の場所から再開できます。

このData Science Academyレッスンでコードを書いて実行できますか?

はい。すべてのData Science Academyレッスンに組み込みコードエディタが含まれているため、ブラウザでリアルコードを書いて実行し、即座のAIフィードバックを取得できます。ローカル設定は不要です。

このコースのすべてのレッスン

  1. read_csvと便利なオプション
  2. pandasでExcelシートを開く
  3. 読み込み時に日付を解析してdtypeを設定
  4. 結果をCSVとExcelに保存
← Data Science Academyに戻る