我有一个产品系列的大型数据集。我正在尝试捕获任何奇怪的数据条目,这些条目的价格比其他家庭成员的价格太高/太低。例如,我有一个this 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循环,它遍历每个Product Family,设置某种阈值来识别哪些产品有问题(第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语句。有没有人有关于如何设置这个阈值和完成代码的想法(或者更好的想法)?
转载请注明出处:http://www.cdylmjg.com/article/20230401/2304726.html