我是Python語言的新手,我面臨的是一個小小的挑戰,到目前爲止瞭解它。 我收到一個csv文件,大約30-40列,5-50行,每個單元格中有各種細節。 csv的第一行有每列的標題,第二行有我的項目值。 我想要做的是創建一個python腳本,它將讀取csv文件,並且每次都執行以下操作: 在實際的第一項行之後添加一行(字面意思是在第二行之後,導致第一行是標題),並在新的第三行中包含與上面相同的信息,只有一個區別。在「item_subtotal」列中,我想添加「折扣總額」列中的值。 所有波紋管行應保持原樣,並將此修改後的csv保存爲新文件,並在文件名中添加單詞「編輯」。 我真的可以使用一些幫助,因爲到目前爲止我只設法打開一個python腳本即時通訊開發csv文件,但我不能夠到目前爲止添加上述行的內容到新創建的行並替換該特定值。 期待任何幫助。 謝謝如何在python中編輯csv並在第二行之後添加一行,除了1之外的所有列中都具有相同的值
這裏我附加CSV的一些值爲了保護隱私的原因。
ORDER_ID,ORDER_NUMBER,日期,狀態,shipping_total,shipping_tax_total,fee_total,fee_tax_total,TAX_TOTAL,discount_total,ORDER_TOTAL,refunded_total,order_currency,PAYMENT_METHOD,SHIPPING_METHOD,CUSTOMER_ID,billing_first_name,billing_last_name,billing_company,billing_email,billing_phone,billing_address_1,billing_address_2, billing_postcode,billing_city,billing_state,billing_country,shipping_first_name,shipping_last_name,shipping_address_1,shipping_address_2,shipping_postcode,shipping_city,shipping_state,shipping_country,shipping_company,customer_note,ITEM_ID,item_product_id,ITEM_NAME,item_sku,item_quantity,item_subtotal,item_subtotal_tax,ITEM_TOTAL,item_total_tax,item_refunded,item_refunded_qty, item_meta,shipping_items,fee_items,tax_items,coupon_items,order_notes,download_permissions_granted,admin_custom_order_field:customer_type_5 15001_TE ST_2 ,,「2017-10-09 18:53:12」,處理中,0,0.00,0.00,0.00,5.36,7.06,33.60,0.00,歐元,PayoneCw_PayPal,「0,00」,0,姓名, ,name.surname @ gmail.com,,「address 1」,41541_TEST,location ,, DE,name,姓氏,地址,01245212,14521,location ,, DE ,,, 1328,302,「product title」, 103,1,35.29,6.71,28.24,5.36,0.00,0 ,, 「ID:1329 | method_id:free_shipping:3 | method_title:0,00 |總計:0.00」 ,, ID:1330 | rate_id:1 |代碼: DE-MWST-1 | title:MwSt | total:5.36 | compound:,「id:1331 | code:#getgreengent | amount:7.06 | description:Launchcoupon for friends」,「text string」,1,
發佈輸入文件內容和預期結果 – RomanPerekhrest
牆上的文本,沒有輸入數據的例子,沒有預期的輸出。 Downvoted。請閱讀:https://stackoverflow.com/help/how-to-ask –
嗨安東, 我編輯了我的文章並添加了示例數據。對不起我的菜鳥錯誤。請遵循指南。 –