代码如下;
import pandas as pd
import numpy as np
data = {'name': ['Joe', 'Mike', 'Jack', 'Rose', 'David', 'Marry', 'Wansi', 'Sidy', 'Jason', 'Even'],
'age': [25, 32, 18, np.nan, 15, 20, 41, np.nan, 37, 32],
'gender': [1, 0, 1, 1, 0, 1, 0, 0, 1, 0],
'isMarried': ['yes', 'yes', 'no', 'yes', 'no', 'no', 'no', 'yes', 'no', 'no']}
labels = ['name', 'age', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j']
df = pd.DataFrame(data, index=labels)
df.loc()
按住CTRL鼠标点击loc,定位到loc函数,发现loc是属性方法,带有@property装饰器如图所示:
问题:
既然loc是属性方法,那代码中 df.loc()应该报错 如“”* is not callable“才对吧?为什么系统不会报错?