将过滤器应用于paandas数据框后获取空索引

时间:2018-03-08 07:47:19

标签: python pandas

我正在尝试将过滤器应用于pandas数据帧,但获取空索引
我的df看起来像这样

enter image description here

我的代码是......

df = pd.DataFrame(list(boh), columns = ['MATERIAL', 'Plant', 'BOM Usage', 'Alt. BOM', 'Valid-From Date'])  
print df  
Alternate_bom = df['Alt. BOM'] == 1  
print df[Alternate_bom]

1 个答案:

答案 0 :(得分:0)

我认为需要按字符串'1'进行比较:

df1 = df[df['Alt. BOM'] == '1']

另一种可能的解决方案是将列转换为int

df1 = df[df['Alt. BOM'].astype(int) == 1]

或者:

df['Alt. BOM'] = df['Alt. BOM'].astype(int)
df1 = df[df['Alt. BOM'] == 1]
相关问题