【问题标题】:How to retrieve data if you know the column value and row value using a pandas data frame? [duplicate]如果您使用 pandas 数据框知道列值和行值,如何检索数据? [复制]
【发布时间】:2019-03-10 11:49:15
【问题描述】:

如果我有这样的熊猫数据框:

   A  B  C  D  E  
1  3  4  2  5  1
2  5  4  2  4  4
3  5  1  8  1  3
4  1  1  9  9  4
5  3  6  4  1  1

想要找到行值为 3 列值为 D 的值,我该怎么做?

在这种情况下,我的行值为 3,列值为 D,在这种情况下,我如何获得 1 的返回值?

或者,如果我的行值为 2,列值为 B,我将如何获得 4 的回报?

【问题讨论】:

  • 字面意思是df.loc[3, 'D'],或df.loc[2, 'B']

标签: python python-2.7 pandas


【解决方案1】:

您可以使用DataFrame.loc:df.loc[row, 'col_name'],例如df.loc[2, 'B'] for 4

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-10-05
    • 2017-10-21
    • 2016-11-14
    • 2023-03-03
    • 1970-01-01
    • 1970-01-01
    • 2017-07-18
    • 2013-12-16
    相关资源
    最近更新 更多