Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The Pandas data frame head looks as follows I have grouped the states and sorted the dates. Also, the Day column starts with 2020-03-01 as

The Pandas data frame head looks as follows

image text in transcribed

I have grouped the states and sorted the dates. Also, the "Day" column starts with "2020-03-01" as the first day and today's date as the last day. Example -- If the state started recording cases on "2020-03-13" as shown by Alabama above, this would be the 13th day. I wanted to find the average day of a case. I used the following code to do so.

image text in transcribed

Where 'Avg day of case" is just a null values column. However, when I do this, I get an error message of key error 0. I am trying to replicate the formula in excel shown below, which does work. How would I do this in Pandas and in Python?

image text in transcribed

date state Deaths Cases Day 0 0 2020-03-13 2020-03-14 2020-03-15 2020-03-16 2020-03-17 AL AL AL AL AL 0 6 12 23 29 39 13.0 14.0 15.0 16.0 17.0 0 0 Iterating from the second row till the end and finding the value for i in range(1, len(df)): # Formula Xabccdf.lockin' Cases'l-df.locline Cases lentuldf.loclin Daxil-df.loclizin' Avg day of case'huildf.loclin Cases llentuldf.locki-te'Avg day of case'll # Rounding to 2 decimal places df.loc[i, 'Avg day of case'] = round(x,2) df.head() B D E F G 1 2 date day state cases deaths Avg day of case day 12 3 4 61 1 13.001 131 14] =+(D5-04)*($B5)-G4)/(D5)+G4 5 121 6 23 15 14.22 2020-03-13 2020-03-141 2020-03-15 2020-03-16 2020-03-17 2020-03-18 13 Alabama 14 I Alabama 15 Alabama 16 Alabama 17 Alabama 18 Alabama O O O O O O 7 29 16 8 39 17 18 14.59 15.21 15.86 9 51

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

Differentiate the function. r(z) = 2-8 - 21/2 r'(z) =

Answered: 1 week ago

Question

4. Develop a self-directed learning module.

Answered: 1 week ago

Question

2. Provide recommendations for effective on-the-job training.

Answered: 1 week ago