I'm trying to figure out how to add another row called '4' to the following dataframe such that that row calculates the first row minus the second row for each respective column. I have tried finding the solution through similar questions that were posted on this website, but I find them to be extremely confusing and not very helpful as I am completely new to Python. Is there a simple way to do this?
Asked
Active
Viewed 40 times
0
-
1Welcome to StackOverflow. Please take the time to read this post on [how to provide a great pandas example](http://stackoverflow.com/questions/20109391/how-to-make-good-reproducible-pandas-examples) as well as how to provide a [minimal, complete, and verifiable example](http://stackoverflow.com/help/mcve) and revise your question accordingly. These tips on [how to ask a good question](http://stackoverflow.com/help/how-to-ask) may also be useful. – jezrael Mar 03 '18 at 18:17
-
but maybe need `df.loc[4] = df.loc[0] - df.loc[1]` – jezrael Mar 03 '18 at 18:18
-
Please don't post pictures of code and error messages on SO, post the text here on SO. – Mr. T Mar 03 '18 at 18:20
-
Thanks! This worked. Do you know if it works differently if you use strings as an index instead of just simple numbers? I'm trying to reproduce the same thing for strings but I keep getting a lot of errors. – Mathijs Moonen Mar 03 '18 at 18:28
-
@MathijsMoonen - Please check linked dupe, it is exactly what you need. – jezrael Mar 03 '18 at 18:29