Just wanted a possible solution for iterating a difference over columns. Intuition says a simple for loop should be able to solve it, however, it's been a while and I am super rusty with my syntax etc. Or a group by with a lambda function?
Problem statement.
df looks like:
Obviously working with cohort files. I want to find the difference for col(n+1) - col(n) and iterate while grouping over the cohort group.
This simple call should do the trick:
df.diff(-1, axis=1)
diff
's axis=1
will calculate a difference on the column axis. Check the doc here
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.