Help us understand the problem. What is going on with this article?

pandasの便利関数

kaggleを始めたのですが、データの前処理でどうすればいいか途方にくれることが多いです。
karnelを読んで見つけたDataFrameの前処理・可視化に便利そうな関数のメモです。

dfは読み込まれてる前提です。

カラムの型、カラムのNanデータ数を一覧表示

df.info()

カラムのデータ例、平均、分散、標準偏差などを一覧表示

df.describe(include='all')

Nanデータの多いカラム順にソート

df.isna().sum().sort_values(ascending=False)

グラフ表示

missing = df.isna().sum().sort_values(ascending=False)
sns.barplot(missing, missing.index)
plt.show()

入れ子の文字列をリストと辞書に変換

csvのフィールドに以下のようなデータが文字列として格納されている場合がよくあります。

[{'id': 53, 'name': 'Thriller'}, {'id': 18, 'name': 'Drama'}]

この文字列はPythonのリストの中に複数の辞書が入っています。

import ast

x = "[{'id': 53, 'name': 'Thriller'}, {'id': 18, 'name': 'Drama'}]"

converted_x = ast.literal_eval(x)

literal_evalで文字列をリストや辞書に変換できます。

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away