我目前正在尝试计算CSV文件的一列中的重复值,并将该值返回到python中的另一个CSV列。在
例如,我的CSV文件:
KeyID GeneralID
145258 KL456
145259 BG486
145260 HJ789
145261 KL456
我想要实现的是计算有多少数据具有相同的GeneralID
,并将其插入到一个新的CSV列中。例如
我尝试过使用split方法拆分每一列,但效果不太好。在
我的代码:
case_id_list_data = []
with open(file_path_1, "rU") as g:
for line in g:
case_id_list_data.append(line.split('\t'))
#print case_id_list_data[0][0] #the result is dissatisfying
#I'm stuck here..
您必须将任务分为三个步骤: 1读取CSV文件 2生成新列的值 三。为文件添加价值 导入csv 导入文件输入 导入系统
我没有使用临时文件或任何高级模块,如熊猫或任何东西。在
如果你不喜欢熊猫,想留在标准图书馆:
代码:
结果:
^{pr2}$相关问题 更多 >
编程相关推荐