【问题标题】:Pandas column selection with coordinates带有坐标的 Pandas 列选择
【发布时间】:2017-08-23 05:03:15
【问题描述】:
我有一个熊猫数据框:
A.loc[:,:,location]
location = (x, y)
x 和 y 数字。当我尝试选择列时:
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)')]