【问题标题】:Pandas column selection with coordinates带有坐标的 Pandas 列选择
【发布时间】:2017-08-23 05:03:15
【问题描述】:

我有一个熊猫数据框:

A.loc[:,:,location]

location = (x, y) xy 数字。当我尝试选择列时: locations = (1, 2) 在:

B = A.loc[:,:,location]

它说:'[(1, 2)] 不在列中。' 当我打印数据框时,它清楚地表明 (1, 2) 在短轴上。 知道如何选择这些类似坐标的列吗?

【问题讨论】:

    标签: pandas numbers coordinates col


    【解决方案1】:

    至少对我来说,你还不清楚你想要什么,但也许这些会有所帮助:

    # Select the first 3 columns
    df.iloc[:,:3]
    
    # Select the first cell down in the column named location
    df.ix[0, 'location']
    
    # Select all the location rows has the value of "(1,2)"
    df[(df['location'] == '(1,2)')]
    

    【讨论】:

    • 如果你澄清你想要什么,我可以尽力帮助你
    • .ix 成功了,不知道那个命令。感谢您的帮助!
    猜你喜欢
    • 2018-10-23
    • 2015-10-03
    • 2022-01-13
    • 2020-11-07
    • 1970-01-01
    • 2016-12-03
    • 1970-01-01
    • 1970-01-01
    • 2017-06-06
    相关资源
    最近更新 更多