Home > other >  The While loop, the output is only the result of the last operation, how to extract all the results
The While loop, the output is only the result of the last operation, how to extract all the results

Time:10-02

The import pandas as pd
The import re
Import the collections


ExcelFile='2. XLSX'
Df=pd DataFrame (pd) read_excel (excelFile))
Cblist=[]
Df1=df [' Object description '] dropna (how='all')
For the name in df1:
If the '10' in name:
Cblist. Append (name)
Df3=pd. DataFrame
Df4 axle=pd. DataFrame
List=[]
A=0
While a<(len (cblist)) :
For the op in cblist [a] :
Df2=df. Loc [df [' Object description ']==cblist [a]]
Cablelist2=df2 [[' Object ID ']] values. T.t olist () [:] [0]
For the op in cablelist2:
DfByID=df. Loc [df [' under rev. Parts no. ']==op]
Print (' \ r \ n ')
Df3=df2. Append (dfByID)
Sorted_df3=df3. Sort_index ()
Df4 axle=sorted_df3. Update
Print (sorted_df3)
Break
A +=1


The result of the expected output as follows, the result also want to write excel spreadsheets, therefore how to all sorted_df3 results together?
Sort Lev under rev. Parts no.... 1
Net Gross Quantity.20 4074... 3 10263305... 1.017 1.017 1
21 4075... 4 10259566... 0.000 0.000 1
22 4076... 4 10259566... 0.005 0.005 5
23, 4077... 4 10259566... 0.005 0.005 5
24 4078... 4 10259566... 0.001 0.001 1

[5 rows x 36 columns]


Sort Lev under rev. Parts no.... 1
Net Gross Quantity.25, 4131... 3 10263305... 1.03 1.03 1
26 4132... 4 10259573... 0.00 0.00 1

[2 rows x 36 columns]


The results can only output

Append this instruction to use sorted_df3 because every time the output is not the same but the name is the same, every time can't define the name of the output,

Thank you for reading

CodePudding user response:

CodePudding user response:

The building Lord problem solved yet? I also just learning python, when doing the loop to output this cycle the full results of many times, but despite repeated attempts, the output is always the result of the last
  • Related