dataframe 数据结构,取其中一个数

img

图中是一个datafram数据结构,cdefgh为值,我想通过cde得到fgh,相当于构建一个虚拟的字典结构,c对应f的值,d对应g的值,e对应h的值


import pandas as pd
data_str = [['c','f'],['d','g'],['e','h']]

df1 = pd.DataFrame(data_str,columns=['a','b'])

xdic = {}
for row in df1.iterrows():
    xdic[row[1][0]] = row[1][1]

print(xdic)

df = pd.DataFrame([['c', 'f'], ['d', 'g'], ['e', 'h']], columns=['a', 'b'])
dct=df.set_index('a').T.to_dict(orient='records')
print(dct)