我从一个网站上刮了一些数据,我想将其存储在Excel中。该过程工作正常,但问题是它一次又一次地将新数据覆盖到第一行。这是我用来将数据追加到Excel文件的代码:`head =命名元组(“发票”,'''PDF_FormatType AR_Configuration_Name DOB Client_Id Provider_Name Provider_Address TAX_ID NPI_Number Insurance_Name Insurance_Address CHECK_EFT_Address CHECK_EFT_Number Patient_Name INSURED_NAME PATIENT_CORRECTED_NAME Account_Number Sr_No DateofService_From DateofService_To Insurred_ID INSURED_CORRECTED_ID Type_of_Bill Billed_Amount Paid_Amount Total_Contractual_Amount Deductible_Amount Coninsurance_Amount Co_Pay_金额调整_金额索赔_状态_无索赔_编号计划_名称索赔_已付_日期CROSS_OVER_PAYER_NAME Non_Covered_金额承保_金额DRG_编号DRG_金额总计_允许_金额Medical_Record_编号利息扣押_金额总计_Patient_责任延迟_归档_费用收款人_ID Patient_Group_Policy_No Check_EFT_Date Previously_Paid Forwarded_to_Additional_Payer PATIENT_RESPONSIBILITY_REASON_CODE ASG Processed_As Expected_Reimbursement Rendering_Provider_Name Rendering_Provider_NPI Claim_Status Inboxes_Name Category Queue Inbox_Description Unknown_Inbox_Category OCR_Processed_Date Timestamp Invoice_No Invoice_No_3x''')Claim_Level.append((head(PDF_FormatType,AR_Configuration_Name,p_dob,Client_Id,p_payor,Provider_Address,p_taxid,p_bpnpi,p_renp,Insurance_Address,CHECK_EFT_Address,CHECK_EFT_Number,p_name,INSURED_NAME,PATIENT_CORRECTED_NAME,Account_Number、Sr_No、p_dos、p_dsub、p_ins、INSURED_CORRECTED_ID、p_ctype、Billed_Amount、Paid_Amount、Total_Contractual_Amount、Deductible_Amount、Coninsurance_Amount、Co_Pay_Amount、Adjustment_Amount、Claim_Status_No、p_cnum、Plan_Name、Claim_Paid_Date、CROSS_OVER_PAYER_NAME、Non_Covered_Amount、Covered_Amount、DRG_Number、DRG_Amount、Total_Allowed_Amount、Medical_Record_Number、Interest、扣押金额、Total_Patient_Responsibility、Late_Filing_Charge、Payee_ID、Patient_Group_Policy_No、Check_EFT_Date、Previously_Paid、Forwarded_to_Additional_Payer、PATIENT_RESPONSIBILITY_REASON_CODE、ASG、Processed_As、Expected_Reimbursement、p_renp、p_rpnpi、Claim_Status、Inboxes_Name、Category、Queue、Inbox_Description、Unknown_Inbox_Category、OCR_Processed_Date、time、i、xnum)))
csvgenerater = pd.DataFrame(Claim_Level)
with pd.ExcelWriter('OUTPUT_FILE.xlsx', engine='openpyxl', mode='w') as writer:
.....csvgenerater.to_excel(writer, sheet_name = 'ClaimLevel_Output', startrow=0, startcol=0, index=False)`
(the点是缩进)
这是代码的屏幕截图:enter image description here我希望它逐行存储数据,而不是覆盖它。
1条答案
按热度按时间6rqinv9w1#
您的代码没有提供变量
mode
包含的值的任何信息。请确保它包含附加模式的值'a'
。否则变量csvgenerater
将被写入Excel文件。另一种解决方案是将现有的Excel文件读取为
DataFrame
,追加一行并将追加的DataFrame
保存为Excel文件。