基于iLocation的整数类型的布尔索引不可用

时间:2019-05-21 05:09:32

标签: pandas

我有一个问题,我想获取包含缺失值的那些行。对表中的“里程”列使用iloc和pd.isnull

import pandas as pd
df=pd.read_csv('BikeList.csv')
d1=df['Mileage']
print(d1)
print(pd.isnull(df['Mileage']))
d2=df.iloc[pd.isnull(df['Mileage']),['Bike','Mileage']]

我遇到此错误

iLocation based boolean indexing on an integer type is not available

import pandas as pd
df=pd.read_csv('BikeList.csv')
d1=df['Mileage']
print(d1)
print(pd.isnull(df['Mileage']))
d2=df.iloc[pd.isnull(df['Mileage']),['Bike','Mileage']]

1 个答案:

答案 0 :(得分:1)

您需要使用DataFrame.loc,因为按标签<uses-permission android:name="android.permission.GET_ACCOUNTS"/> Bike进行选择:

Mileage

或使用Series.isna

d2 = df.loc[pd.isnull(df['Mileage']),['Bike','Mileage']]

如果需要DataFrame.iloc,则将布尔掩码转换为numpy数组,但也可以将列转换为Index.get_indexer的列位置:

d2 = df.loc[df['Mileage'].isna(),['Bike','Mileage']]

示例

d2 = df.iloc[pd.isnull(df['Mileage']).values, df.columns.get_indexer(['Bike','Mileage'])]