【发布时间】:2018-01-31 03:07:57
【问题描述】:
如果 P/E 位于我的数据框中所有 P/E 的下四分位数,我正在尝试创建一个返回 True 的列。以下是我到目前为止所做的。
首先我定义了一个函数:
def pe_cond(df):
if df['P/E'] <= df['P/E'].quantile(0.1):
return 1
else:
return 0
其次,我尝试将它应用到我的数据框
df['pe_cond'] = df.apply(pe_cond, axis=1)
但是我得到以下错误:
AttributeError: ("'float' object has no attribute 'quantile'", u'occurred at index 0')
任何帮助将不胜感激。
谢谢
【问题讨论】:
-
df['pe_cond'] = (df['P/E'] <= df['P/E'].quantile(0.1)).astype(int) -
感谢您的评论,这是一种享受