0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

DataFrameに関する関数

Last updated at Posted at 2018-11-26

列名が同じときに1つだけ残して同じ名前の列を除く関数

def del_duplicate_columns(df):
    """this function removes columns if they have the same name"""
    ret_list=df.columns.tolist()
    ret_result=[]
    for i in range(len(ret_list)):
        if ret_list[i] not in ret_list[0:i]:
            ret_result.append(i)
    return df.iloc[:,ret_result]

季節調整ダミー変数行列の作成

import pandas as pd

def df_seag(index_len=24, seag=12):
    df_seag=pd.DataFrame(0, index=range(index_len), columns=range(seag-1))
    for i in range(index_len):
        if i%seag != seag-1:
            df_seag.iloc[i,i%seag]=1
    return df_seag

df dropper

def df_dropper(df, criteria=0.05):
    '''delete row if it is not densed enough'''
    df=df.reset_index()
    list_to_del=[]
    for i in range(len(df.index)):
        r=df.iloc[i,:]
        if sum(r==r) / len(r) <0.05:
               list_to_del.append(i)
    df.drop(list_to_del, axis=0)
    return df
0
0
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?