Pandas loc和no loc的布尔选择

Pandas loc和no loc的布尔选择,pandas,Pandas,是否有以下不同的选项 dfCombined[col][dfCombined[col].isnull()] dfCombined[col].loc[dfCombined[col].isnull()] 我检查了iloc,和ix,它们不支持布尔选择?我认为如果需要过滤列col使用loc: dfCombined.loc[dfCombined[col].isnull(), 'col'] 如果需要,可以省略所有列loc: dfCombined[dfCombined[col].isnull()] 样本:

是否有以下不同的选项

dfCombined[col][dfCombined[col].isnull()]
dfCombined[col].loc[dfCombined[col].isnull()]
我检查了
iloc
,和
ix
,它们不支持布尔选择?

我认为如果需要过滤列
col
使用
loc

dfCombined.loc[dfCombined[col].isnull(), 'col']
如果需要,可以省略所有列
loc

dfCombined[dfCombined[col].isnull()]
样本:

dfCombined = pd.DataFrame({'col':[1,2,np.nan],
                   'col1':[4,5,6]})

print (dfCombined)
   col  col1
0  1.0     4
1  2.0     5
2  NaN     6

print (dfCombined.loc[dfCombined['col'].isnull(), 'col'])
2   NaN
Name: col, dtype: float64

#select second column (1)
print (dfCombined.ix[dfCombined['col'].isnull(), 1])
2    6
Name: col1, dtype: int64

print (dfCombined.iloc[dfCombined['col'].isnull(), 1])
NotImplementedError: iLocation based boolean indexing on an integer type is not available

print (dfCombined[dfCombined['col'].isnull()])
   col  col1
2  NaN     6
关于你的问题:

这两种方法都适用,但更可取的是选择列的
ix
loc
——请参阅

我认为如果您需要使用过滤列
col
使用
loc

dfCombined.loc[dfCombined[col].isnull(), 'col']
如果需要,可以省略所有列
loc

dfCombined[dfCombined[col].isnull()]
样本:

dfCombined = pd.DataFrame({'col':[1,2,np.nan],
                   'col1':[4,5,6]})

print (dfCombined)
   col  col1
0  1.0     4
1  2.0     5
2  NaN     6

print (dfCombined.loc[dfCombined['col'].isnull(), 'col'])
2   NaN
Name: col, dtype: float64

#select second column (1)
print (dfCombined.ix[dfCombined['col'].isnull(), 1])
2    6
Name: col1, dtype: int64

print (dfCombined.iloc[dfCombined['col'].isnull(), 1])
NotImplementedError: iLocation based boolean indexing on an integer type is not available

print (dfCombined[dfCombined['col'].isnull()])
   col  col1
2  NaN     6
关于你的问题:

这两种方法都适用,但更可取的是选择列的
ix
loc
——请参阅


在pandas
df中,iloc
仅适用于布尔值

例如:

df.iloc[df[‘col’]==False/True] 
其中as
df.loc
适用于非布尔值

例如:

df.loc[df[‘col’]==values]

在pandas
df中,iloc
仅适用于布尔值

例如:

df.iloc[df[‘col’]==False/True] 
其中as
df.loc
适用于非布尔值

例如:

df.loc[df[‘col’]==values]