dtypeと重複行を修正する
型を変換し、重複を削除する
「dtypeと重複行を修正する」はCoddyKit上の無料Data Science Academyレッスンです。 これはレッスン4/4です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応のAIチューターでハンズオン演習できます。 これはData Science Academy学習パスの一部であり、ウェブとCoddyKitアプリ全体で進捗が同期されます。 Data Science Academyコースには全4レッスンが含まれています。
このレッスンの一部はまだ翻訳されておらず、英語で表示されています。
Clean Goes Beyond Gaps
Filling missing values is only half the job. Clean data also needs correct dtypes and no accidental duplicate rows muddying your counts. 🧹
What a dtype Is
Every column has a dtype, its data type, like int, float, object, or datetime. The dtype controls which operations the column even allows.
df.dtypesNumbers Stuck as Text
A frequent mess: numbers loaded as object strings because one stray symbol crept in. You cannot do math on them until the type is fixed.
Coerce With to_numeric
Convert a text column to numbers with to_numeric. Pass errors='coerce' to turn anything unparseable into NaN instead of crashing.
df['price'] = pd.to_numeric(df['price'], errors='coerce')Cast With astype
When a column is already clean, astype changes its type directly, for example turning whole-number floats back into compact integers.
df['count'] = df['count'].astype(int)Fix Date Columns
Dates often arrive as text. Convert them with to_datetime so you can sort, filter by range, and extract parts like month later.
df['date'] = pd.to_datetime(df['date'])Category to Save Memory
Columns with few repeated text values shrink dramatically as the category dtype, which stores each label once and references it.
df['city'] = df['city'].astype('category')Spotting Duplicate Rows
Repeated records inflate totals and averages. Find them with duplicated(), which flags each row that has appeared before as True.
df.duplicated().sum()Dropping Duplicates
Remove repeats with drop_duplicates(). By default it keeps the first occurrence of each row and discards the rest.
df = df.drop_duplicates()Duplicates by Key Columns
Sometimes only certain columns define a duplicate. Pass subset to detect repeats based on a key like an id, ignoring the other columns.
df.drop_duplicates(subset=['user_id'])Verify Before You Move On
After fixing types and repeats, run info() once more. Confirming dtypes and row counts protects you from cleaning errors slipping downstream.
df.info()Quick Check
A price column loaded as object text. Which call safely turns bad entries into NaN?
Recap: Types and Dupes Tamed
You now fix dtypes with to_numeric, astype, and to_datetime, and clear repeats with drop_duplicates. Your table is finally analysis-ready.
よくある質問
「dtypeと重複行を修正する」レッスンは無料ですか?
はい。「dtypeと重複行を修正する」の完全なテキストはこのウェブで無料で読めます。インタラクティブに演習し(組み込みコードエディタと24時間対応のAIチューター)、Data Science Academyコースの残りをアンロックするには、CoddyKit PROにアップグレードしてください。 Data Science Academyコースには全4レッスンが含まれています。
「dtypeと重複行を修正する」で何を学びますか?
型を変換し、重複を削除する ブラウザで直接実行するハンズオンコードでData Science Academyを演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。
Data Science Academyを始めるのに経験は必要ですか?
事前経験は必要ありません。CoddyKitのData Science Academyは初級者から上級者向けに構成されているため、ここから始めるか最初から始めて、自分のペースで進むことができます。 これはレッスン4/4です。
「dtypeと重複行を修正する」レッスンにはどのくらい時間がかかりますか?
ほとんどのCoddyKitレッスンは約5~10分かかります。各レッスンはコンパクトでインタラクティブなので、着実に進歩し、ウェブとアプリ全体で正確に前回の場所から再開できます。
このData Science Academyレッスンでコードを書いて実行できますか?
はい。すべてのData Science Academyレッスンに組み込みコードエディタが含まれているため、ブラウザでリアルコードを書いて実行し、即座のAIフィードバックを取得できます。ローカル設定は不要です。
このコースのすべてのレッスン
- テーブルに潜むNaNを見つける
- 削除か補完か:賢く選ぶ
- 平均、中央値、最頻値で補完する
- dtypeと重複行を修正する