簡體   English   中英

使用腳本根據其他列值提取 excel 列值

[英]Extract excel column values based on other column values using script

我有以下 excel 表:

數據

我需要根據評論列分離數據。 如果 Comment 列的值相同,那么我只需要檢索名稱、端口值,如下所示:

###LSB Team
super_bot0,DstSdp00_Prb
super_tot0,DstSd_PrbAddr

###ESB Team
supe_bot0,IOHC_Vld
subot0_3,IOHC_DVMSyncComplete

誰能幫我自動化這個。

你能在你的 excel 文件上運行它嗎?

import pandas as pd

df = pd.read_excel('book1.xlsx')

comment_to_teams = {}
for comment, rows in df.groupby('Comment'):
    comment_to_teams[comment] = rows[['Name', 'Port']]

for comment, teams in comment_to_teams.items():
    print(comment)
    print(teams)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM