【问题标题】:Get column index that matches list values获取与列表值匹配的列索引
【发布时间】:2021-07-13 14:36:15
【问题描述】:

我正在尝试从与列表中的值匹配的数据框行中获取列号/索引。 我有这个:

pos=local.loc[[row_to_verify]].isin(global.index[global['cond'] == 'F'].tolist())

从这部分:

global.index[global['cond'] == 'F'].tolist()

我收到了list=[1,3]。我想使用这些值来选择local[row_to_verify] 的哪些列与获取的列表中的值匹配。

【问题讨论】:

    标签: python pandas dataframe


    【解决方案1】:

    你能添加更具体的例子吗?最好的办法是查看您想要的 df 和您的输出。首先,我以为您想获取指定列中精确值的索引,但现在我看到您想要列号,但我看不到这一点,示例会有所帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-11-13
      • 1970-01-01
      • 1970-01-01
      • 2023-02-01
      • 2020-06-07
      • 1970-01-01
      • 2015-11-10
      • 2015-02-12
      相关资源
      最近更新 更多