import pandas as pd
path="./1.csv"
data=pd.read_csv(path)
data.head()
#输出结果显示
'''
No interpreted age TOC (wt%) P (wt%) N (wt%)
64533.0 1.0 NaN 0.030538 NaN
72350.0 1.0 NaN 0.074163 NaN
89049.0 1.0 NaN NaN NaN
121476.0 1.0 0.37 0.000000 NaN
124133.0 1.0 NaN 0.054200 NaN
'''
data.set_index('No',inplace=True)
data.index
#输出结果显示
'''Float64Index([ 64533.0, 72350.0, 89049.0, 121476.0, 124133.0, 124159.0,
89050.0, 89051.0, 89052.0, 89053.0,
...
110607.0, 110608.0, 110609.0, 110610.0, 110611.0, 110612.0,
110613.0, 110614.0, 110615.0, 110616.0],
dtype='float64', name='No', length=124558)'''
def tool_1_data(data):
return data.index.astype(str).startswith(1) & (data["interpreted age"]<1000)
data.loc[tool_1_data,:]
想自定义一个函数查找’No‘这一列中有’1‘的,且’interpreted age‘<1000的,但是总是报错”
AttributeError: 'Index' object has no attribute 'startswith' 实在是没搞懂,求解