Home > other >  Python office automation processing data, traverse the query meet the conditions specified values re
Python office automation processing data, traverse the query meet the conditions specified values re

Time:12-30

Everyone, Python office automation processing data, traverse the query meet the conditions specified values revision

Could you tell me how to traverse the EXCEL when the condition order status as "success", the "amount" zero "15" instead, the order status as a "failure", the "amount" value instead of 15 "0", and the modified values in the original file directly save

The present situation is:
1. After the code to run only on the last statement execution, the only change the failure or success conditions in numerical
2. How to save directly after the modification of numerical value to an existing EXCEL file rather than save as to save

The code is as follows:

The import pandas as pd

Pd. Set_option (' display. Max_columns, 1000)
Pd. Set_option (1000) '. The display width,


Df=pd read_excel (test1. XLSX, sheet_name='sheet1', engine='openpyxl')

S1=df [(df [' order status']=="success")]

S1. Loc [s1 [' amount ']!=15, 'FenRun amount]=15

Dataframe=pd. Dataframe (s1)

Print (s1)

S2=df [(df [' order status']=="failure")]

S2. Loc [s2 [' amount ']!=0, the 'amount']=0

Dataframe=pd. Dataframe (s2)

Print (s2)

CodePudding user response:

What is your "FenRun amount", is to add a new column
  • Related