csv.DictReader()读取和加载文件,然后根据一列的值处理另外一列的值。
代码很简单,看看就知道啥意思了。
# -*- coding:utf-8 -*-
#author:zgd
import pandas
import csv
with open("url_features_3_zgd.csv", 'r') as f:
train_csv = csv.DictReader(f)
firm_type = []
not_firm_type = []
for row in train_csv:
if row["firmware_bool"] == "1":
if row["getContentType"] not in firm_type:
firm_type.append(row["getContentType"])
elif row["firmware_bool"] == "0":
if row["getContentType"] not in not_firm_type:
not_firm_type.append(row["getContentType"])
else:
print "----------"
print firm_type
print not_firm_type