python 去掉只出现一次的类别

 	fileName = file_name
    csvfile = open(fileName , 'rb')  # 打开csv文件
    reader = pd.read_csv(csvfile)  # 读取文件内容
    # print(reader['label'].value_counts())
    aps = reader['label'].value_counts()
    one = (aps== 1)  ###
    # print(aps[one])
    reader = reader[(~reader['label'].isin(list(aps[one].index)))]
    # print(reader['U_CODE'].value_counts())
    reader.to_csv(outputFile,index=0)

你可能感兴趣的:(代码段)