Pythonのデータ分析:パンダのデフォルトの分析

Pythonのデータ分析:パンダのデフォルトの分析

背景

私たちは、NaNのデータベースやNATから変換パンダなしにデータを抽出しました。しかし、我々は、データがデータベースに書き込まれているパンダなり、時間となしに変換する必要がある、それ以外の場合はエラーになります。したがって、我々は、パンダのデフォルト値に対処する必要があります。

サンプルデータ

   id         name  password  sn  sex  age  amount  content  remark  login_date login_at    created_at  
0   1  123456789.0       NaN NaN  NaN   20     NaN      NaN     NaN  NaN        NaT         2019-08-10 10:00:00  
1   2          NaN       NaN NaN  NaN   20     NaN      NaN     NaN  NaN        NaT         2019-08-10 10:00:00 

デフォルト値が決定されます

もしcolumnデフォルト値、Noneに統一契約。

def judge_null(column):
    if pd.isnull(column):
        return None
    return column

処理のデフォルト設定

カラム処理のデフォルトによって。

df['id'] = df.apply(lambda row: judge_null(row['id']), axis=1)
df['name'] = df.apply(lambda row: judge_null(row['name']), axis=1)
df['password'] = df.apply(lambda row: judge_null(row['password']), axis=1)
df['sn'] = df.apply(lambda row: judge_null(row['sn']), axis=1)
df['sex'] = df.apply(lambda row: judge_null(row['sex']), axis=1)
df['age'] = df.apply(lambda row: judge_null(row['age']), axis=1)
df['amount'] = df.apply(lambda row: judge_null(row['amount']), axis=1)
df['content'] = df.apply(lambda row: judge_null(row['content']), axis=1)
df['remark'] = df.apply(lambda row: judge_null(row['remark']), axis=1)
df['login_date'] = df.apply(lambda row: judge_null(row['login_date']), axis=1)
df['login_at'] = df.apply(lambda row: judge_null(row['login_at']), axis=1)
df['created_at'] = df.apply(lambda row: judge_null(row['created_at']), axis=1)

データの処理が完了した後

   id         name  password  sn    sex    age   amount    content  remark  login_date  login_at  created_at  
0   1  123456789.0      None  None  None   20    None      None     None    None        None      2019-08-10 10:00:00  
1   2         None      None  None  None   20    None      None     None    None        None      2019-08-10 10:00:00 

サプリメント

すべての行、列、価値の長さの表示を設定します。

# 显示所有列
pd.set_option('display.max_columns', None)
# 显示所有行
pd.set_option('display.max_rows', None)
# 设置value的显示长度为100,默认为50
pd.set_option('max_colwidth', 100)

内蔵対応するデータベーステーブルの声明

create table test
(
  id         int(10)        not null primary key,
  name       varchar(32)    null,
  password   char(10)       null,
  sn         bigint         null,
  sex        tinyint(1)     null,
  age        int(5)         null,
  amount     decimal(10, 2) null,
  content    text           null,
  remark     json           null,
  login_date date           null,
  login_at   datetime       null,
  created_at timestamp      null
);

おすすめ

転載: www.cnblogs.com/yxhblogs/p/11330927.html