我有一个问题,我想获取包含缺失值的那些行。对表中的“里程”列使用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']]
答案 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'])]