Python 使用pandas元素作为字典中的键

Python 使用pandas元素作为字典中的键,python,pandas,dictionary,Python,Pandas,Dictionary,我有一本字典: fdict={“X”:['tf'、'pytorch'、'keras']、“Y”:['Gym'、'Scikit']} 以及带有列c1和c2的数据帧df: c1 c2 比索 Y长 X迈斯特 我想得到: fdict[df['c1']]中的'pytorch'作为布尔响应,在这种情况下,它将是真的与lambda函数和get一起使用,输出为布尔值系列: m = df['c1'].apply(lambda x: 'pytorch' in fdict.get(x, None)) print (m

我有一本字典:
fdict={“X”:['tf'、'pytorch'、'keras']、“Y”:['Gym'、'Scikit']}
以及带有列
c1
c2
的数据帧
df

  • c1 c2
  • 比索
  • Y长
  • X迈斯特
  • 我想得到: fdict[df['c1']]中的'pytorch'作为布尔响应,在这种情况下,它将是
    真的

    与lambda函数和
    get
    一起使用,输出为布尔值
    系列

    m = df['c1'].apply(lambda x: 'pytorch' in fdict.get(x, None))
    print (m)
    0     True
    1    False
    2     True
    Name: c1, dtype: bool
    
    如果要测试是否至少有一个
    True
    添加:

    m1 = df['c1'].apply(lambda x: 'pytorch' in fdict.get(x, None)).any()
    print (m1)
    True