Issue
Let's consider this table below:
Mobile | Battery(mAh) | RAM(GB) | Storage(GB) | ED from Ideal best | ED from Ideal worst |
---|---|---|---|---|---|
Sansung | 1000 | 4 | 2 | ||
iPhone | 8000 | 6 | 3 | ||
Motorola | 3000 | 3 | 1 |
Formula for ED from Ideal best = √(( Battery(mAh)- Max of Battery(mAh))^2 + (RAM(GB) - Max of RAM(GB) )^2 + ( Storage(GB) - Max of Storage(GB))^2)
Formula for ED from Ideal Worst = √(( Battery(mAh)- Min of Battery(mAh))^2 + (RAM(GB) - Minof RAM(GB) )^2 + ( Storage(GB) - Min of Storage(GB))^2)
For instance, value for Samsung mobile should be √((1000-8000)^2+(4-6)^2+(2-3)^2) = 7000.00035714
Can Anyone help me to write a function in Python where these two formulas can apply for each rows for ED from Ideal best and ED from Ideal worst?
So far I've tried this:
df["Euclidean Distance from ideal best"]= np.sqrt((df["Battery(mAh)"]-df["Battery(mAh)"].max()).pow(2) + (df["RAM(GB)"]-df["RAM(GB)"].max()).pow(2) + (df["Storage(GB)"]-df["Storage(GB)"].max()).pow(2))
Solution
It works fine by me. Just change the typo df1
->df
:
df["Euclidean Distance from ideal best"] = np.sqrt(
(df["Battery(mAh)"] - df["Battery(mAh)"].max())**2 +
(df["RAM(GB)"]-df["RAM(GB)"].max())**2 +
(df["Storage(GB)"]-df["Storage(GB)"].max())**2)
Answered By - Tobias Molenaar
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.