我正在写一个python脚本。
我的大部分数据都是在垂直模型中记录的,我希望它们是水平的。在
这是我的数据示例ID,Identifier,Value
1_UK,City,Paris
1_UK,Number of the departments,75
1_UK,Department,Ile de France
1_UK,Habitant,12405426hab
2_UK,City,Ajaccio
2_UK,Number of the departments,2A
2_UK,Department,Corse du Sud
我想去的地方是:
^{pr2}$
在Python中读取CSV文件并不困难。我迷路的地方是我有4个标识符(城市、部门编号、部门和居民)
ID 2峎UK对habitant没有值。我不知道如何在我的代码中表达这一点。在import csv
csvfile = open ("Exercice1.csv",'r',encoding='utf-8')
IDs=[]
identifiers=[]
uniqueIDs=[]
uniqueidentifiers=[]
reader=csv.reader(csvfile)
for row in reader:
IDs.append(ID)
identifiers.append(identifier)
csvfile.close()
#remove duplicate value and keep order as is it.
for i in IDs:
if i not in uniqueIDs:
uniqueIDs.append(i)
for i in identifiers:
if i not in uniqueidentifiers:
uniqueidentifiers.append(i)
然后我就迷路了
zip函数似乎不能满足我的需要,或者我没有正确使用它。在
很高兴听你的建议。在
谢谢你!在