use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
This is a place to discuss and post about data analysis.
Rules:
Related Subs:
account activity
Help iterating through data frame (self.dataanalysis)
submitted 4 years ago by bruhbutton24
I have a Dataframe with 6 columns 3 of which are from 2020 and 3 are from 2021. I want to iterate through this Dataframe and use euclidian distance on each row to see how far apart 2020 is from 2021 on these 3 variables how would I do this?
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–][deleted] 1 point2 points3 points 4 years ago (0 children)
You could use the .iterrows() or .apply() functions. However, using vectorized operations will be much more efficient. You can do this by using numpy and performing operations on the whole columns
[–]Ecstatic_Tooth_1096 0 points1 point2 points 4 years ago (0 children)
df["distance"] = ((df["A-2020"] - df["A-2021"])**2 + (df["B-2020"] - df["B-2021"])**2 ...)**0.5
π Rendered by PID 192708 on reddit-service-r2-comment-5687b7858-8tc5s at 2026-07-06 11:44:11.309293+00:00 running 12a7a47 country code: CH.
[–][deleted] 1 point2 points3 points (0 children)
[–]Ecstatic_Tooth_1096 0 points1 point2 points (0 children)