2016-08-12 6 views
-2
import re 
import pandas as pd 

# my imports 
from job_processing.utils import * 

def get_duplication(rule): 
    try: 
     return re.compile(rule.duplication, re.UNICODE) 
    except re.error: 
     raise re.error 

def run_duplication(rule, df, column): 

    cols = dict() 
    cols["dirty"] = get_column_name(df, column) 
    cols["clean"] = get_unique_column_name(df, "clean") 

    # add a new column for the clean data 
    df.loc[df.duplicated(subset=0, keep='first'),cols["clean"]] = df[cols["dirty"]] 

    # return the dirty dataframe with the clean column appended to the end... 
    return df, df[cols["clean"]].dropna().unique() 

私のorginalファイル重複を削除し、バックエンド(つまり実行時)に一意の値を表示する方法。我々は

 0  1 2 3 4 
0 Jason Miller 42 4 25 
1 Tina  Ali 36 31 57 
2 Jake Milner 24 2 62 
3 Jason Miller 42 4 25 
4 Jake Milner 24 2 62 
5 Amy Cooze 73 3 70 
6 Jason Miller 42 4 25 
7 Jason Miller 42 4 25 
8 Jake Milner 24 2 62 
9 Jake Miller 42 4 25 

以下のような私の要件を除去して、特定の列を与えるでしょう何このコードを実行しています。

 0  1 2 3 4 
0 Jason Miller 42 4 25 
1 Tina  Ali 36 31 57 
2 Jake Milner 24 2 62 
5 Amy Cooze 73 3 70 

Plsはそれを確認して私に提案することができます。ありがとう。

答えて

0

それは必要drop_duplicates次のようになります。

df1 = df.drop_duplicates(subset=[0]) 
print (df1) 
     0  1 2 3 4 
0 Jason Miller 42 4 25 
1 Tina  Ali 36 31 57 
2 Jake Milner 24 2 62 
5 Amy Cooze 73 3 70 

df = pd.concat([df, df1]) 
print (df) 
     0  1 2 3 4 
0 Jason Miller 42 4 25 
1 Tina  Ali 36 31 57 
2 Jake Milner 24 2 62 
3 Jason Miller 42 4 25 
4 Jake Milner 24 2 62 
5 Amy Cooze 73 3 70 
6 Jason Miller 42 4 25 
7 Jason Miller 42 4 25 
8 Jake Milner 24 2 62 
9 Jake Miller 42 4 25 
0 Jason Miller 42 4 25 
1 Tina  Ali 36 31 57 
2 Jake Milner 24 2 62 
5 Amy Cooze 73 3 70 
関連する問題