I have a dataset that counts the total sum of cases daily, but I want to change it so that it only counts the new cases and not the sum. Each column is a date. Is there a way I can do this?
This topic was automatically generated from Slack. You can find the original thread here.
Hi @Irwin_Mier_San_Diego_State_University , it sounds like you may want to simply subtract the previous day’s total from each day? It’s hard to know unless you can share some more info, such as a screenshot of what the data set looks like
Next, assuming all the columns are in order by date, you should be able to for loop through them in reverse order (starting with 9/28/21) and subtracting the column directly to the left, then divide by the zip_pop column. Check out method #5 at this link to see how to loop through the columns by index.
Hi @Ryan_Kruse_MN_State Thank you! I also forgot to mention, I also want to change any negative value I may encounter to zero. If that is also possible
Yes - index using iloc will help you to select the columns you want to subtract & divide. You should be able to find some examples of the subtraction or division if you search something like “pandas columnwise subtraction”
ah ok great. I also forgot to mention, the first columns are postal_codes, which I dont want to remove, but I want the loop to ignore them. Like using a continue method
To prevent any further questions from being overlooked, I’ll go ahead and close this thread out. If you have any more questions or follow-up questions, we’re always here to help! Just be sure to make a new post to help, as we aren’t monitoring old threads at this time. Thanks!