您可以使用以下代碼。
你可以使用下面的代碼。
import os
import pandas as pd
# 創建一個空的字典。
dict = {}。
# 從資料框架中讀取資料 dict = {}。
df = pd.read_excel(r'C:*********Output.xlsx')
#迭代DF
for index in df.index。
# initialize key vairiable with ID columns.
key = df['ID'][index] 。
# If key alreadt exists the append the value which is in list format for else starting
# 添加值到一個串列中。
if key in dict:
dict[key].append(df['藥名'][index])
else:
dict[key] = [df['Medicine Name'][index]]
print(dict)
輸出字典
{53: ['A'/span>, 'B'/span>, 'C'/span>, 'D'/span>, 'E'/span>, 'F'/span>] 。
54: ['G'/span>, 'H'/span>, 'I'/span>, 'J'/span>, 'K'/span>]。
55: ['L', 'M']}。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/311651.html
標籤:

