我有2个.csv
文件,其中包含数千行数据(来自供应商的产品库存)。我需要找到重复和删除价格较高的项目。在
问题是价格包含小数。以下代码是我根据需要完成的最接近的代码:
with open('vendor1.csv', 'r') as venOne, open('vendor2.csv', 'r') as venTwo, open('filtered.csv', 'w') as outFile:
z = csv.reader(venOne, delimiter = ',')
m = csv.reader(venTwo, delimiter = ',')
w = csv.writer(outFile, delimiter = ',')
zupc = {row[5] for row in z} #UPC is in column 5
mupc = {row[5] for row in m}
zprice = {row[9] for row in z} #Price is in column 9
mprice = {row[7] for row in m} #Price is in column 7
for row in z:
if row[5] in mupc and row[9] < mprice:
w.writerow(row)
else:
if row[5] not in mupc:
w.writerow(row)
#Do the same for m
我正在使用Python 2.x
。在
最后,这将使用cron
作业来运行。所有数据都在远程共享服务器上。在
一个警告是我不能使用pandas
(这将节省我编写其他各种脚本的大量时间)。唯一可用的导入模块是python的标准模块,添加附加模块是不可能的(也就是说,不需要花费更多的钱升级到专用服务器)。在
首先,您可能应该使用}。关于价格,你可以试着把它们投射到
dict
,而不是{decimal
。在试试下面的代码,告诉我是否有帮助:
相关问题 更多 >
编程相关推荐