我有一个csv的行产品,如
SKU;price;availability;Time;Supplier;CatCode
x1;10.00;0;1-4-2019;sup1;K1
x1;10.00;0;1-4-2019;sup1;K3
x1;10.00;0;1-4-2019;sup1;K2
另一个csv
CATCODE;MARGIN
K1;0.08
我试着用下面的代码只更新列表行中的一个元素,而每个csv匹配的catcode都是这样。在这种情况下,它应该只更新K1,而其他值保持不变。以下是我尝试的:
def ChangeToFinalCSV():
SetFixMinPrices = SetFixPrices()
CatCodes = GetCatCodes()
for FixMinPrice in SetFixMinPrices:
for cat in CatCodes:
if cat[0] == FixMinPrice[5]:
FixMinPrice[1] = (((float(FixMinPrice[1].replace(',','.').replace('€','')) + float(SupplierShipping)) * float(BankingComission))*(1+float(cat[1]))) * float(1.24)
FixMinPrice[1] = "{:.2f}".format(FixMinPrice[1])
FixMinPrice[1] = str(FixMinPrice[1]).replace('.',',') + ' €'
retailed.append(FixMinPrice)
return retailed
retailed = ChangeToFinalCSV()
但是这个代码改变了所有的元素,不仅仅是K1作为CatCode的行
我想用Python的enumerate来做,但我不知道怎么做。如何仅更新两个文件中的CATCODE匹配的位置?我想用公式new_price=price(1+margin)
把价格乘以保证金。你知道吗
我试着有一个csv像最初的不是熊猫表
就像
SKU;price;availability;Time;Supplier;CatCode
x1;10.80;0;1-4-2019;sup1;K1
x1;10.00;0;1-4-2019;sup1;K3
x1;10.00;0;1-4-2019;sup1;K2
这可以通过熊猫使用merge实现。你知道吗
这是您的原始csv。你知道吗
下面是合并数据帧的最终输出。你知道吗
没有
pandas
,只使用标准python和csv
模块,这里有一种方法。data.csv
是“带产品行的csv”,update.csv
是另一个。你知道吗newdata.csv
现在包含:相关问题 更多 >
编程相关推荐