【发布时间】:2018-06-08 14:11:10
【问题描述】:
我有一个庞大的产品系列数据集。我试图捕捉任何价格比家庭其他成员高/低的奇怪数据条目。比如我有这个pandas.DataFrame:
df =
Prices Product Family
0 1.99 Yoplait
1 1.89 Yoplait
2 1.59 Yoplait
3 1.99 Yoplait
4 7.99 Yoplait
5 12.99 Hunts
6 12.99 Hunts
7 2.99 Hunts
8 12.49 Hunts
我想编写一个 for 循环,遍历每个产品系列,设置某种阈值来识别哪些产品有问题(第 4 行和第 7 行),然后输出该行。我怎样才能做到这一点?
到目前为止,我有这个:
families = df['Product Family'].unique()
for i in families:
if df['Prices] .....(set threshold)
then.....(spit out that row that is questionable)
然后,理想情况下,我会在 for 循环中为每个产品系列完成该 if 语句。有人对如何设置此阈值并完成代码有想法(或更好的想法)吗?
【问题讨论】:
标签: python pandas for-loop dataframe threshold