列名が同じときに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