對于看到的影像,我想將資料值從“Seller id”過濾到“Membership”。但是沒有固定的行值集來進行過濾。例如,如果所有資料值都是 10 個條目,則很好,但這里的場景是 diff 一組有 10 個條目,第二組有 13 個條目。每個賣家 ID 沒有固定的一組行 vales。
你能幫我用python for回圈過濾這個嗎?也開放征求意見!提前致謝!!

uj5u.com熱心網友回復:
鎖了10個小時。對此答案的評論已被禁用,但它仍在接受其他互動。了解更多。如果seller id每個組都有啟動值,請使用:
df = pd.read_excel('sales.xlsx', sheet_name='Sheet2')
#replace substring with regex ^ for start of string and $ for end of string
df['Label'] = df['Label'].str.strip(': ').replace({'</b>':''}, regex=True)
print (df.head())
Label Value
0 seller id 123459876
1 Seller failed verification check on the follow... ABC
2 Marketplace Id 1
3 Distributor Id INFLW
4 Brand AirASIA
#create groups by compare values (each group starting by seller id) with cumulative sum
for i, g in df.groupby(df['Label'].eq('seller id').cumsum()):
print (i)
print (g)
編輯:比較原始值的解決方案,</b>seller id</b> :需要seller id:
df = pd.read_excel('sales.xlsx', sheet_name='Sheet2')
print (df.head())
Label Value
0 </b>seller id</b> 123459876
1 </b>Seller failed transparency check on the fo... ABC
2 </b>Marketplace Id</b> 1
3 </b>Distributor Id</b> INFLW
4 </b>Brand</b> AirASIA
#changed seller id to </b>seller id</b>
for i, g in df.groupby(df['Label'].eq('</b>seller id</b> :').cumsum()):
print (i)
print (g)
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/454567.html
