Getting the quarter where recession start and recession ends along with the quarter of minimum gdp

2024/10/15 5:23:57
Quarter:    GDP:   GDP change:  change
1999q3     9           --         ------
1999q4    10           1          increase
2000q1     9          -1          decline
2000q2     8          -1          decline
2000q3     7          -1          decline
2000q4     6          -1          decline
2001q1     8           1          increase
2001q2     11          3          increase
2001q3     12          1          increase

Here is the Processed dataFrame Now I need separate list of all the quarters in which recession starts ,recession ends and bottom of recession

The start of recession in the example above is '2000q1'because the GDP decline started then

recession end is ''2001q2'

recession bottom is '2000q4' because it has the minimum GDP between start and end

Answer

You can use .loc attribute after setting the quarter the index of the dataframe.

Df.loc[start:end]

You can make the quarter the index of the dataframe using the following statement

Df = Df.set_index('quarter')

Hope that helps.

As asked by you how can you find the recession start and other parameters. Here is the code you can use:

for index in df.index:first_q = df.loc[index, 'gdp']second_q = df.loc[index+1, 'gdp']third_q = df.loc[index +2, 'gdp']

Now the logic is : (if second_q < first_q) and (third_q < second_q) then the first_q is the recession start.

And similarly if second_q > first_q and third_q > second_q then third_q is the recession end.

Basically recession start is the presence of 2 consecutive gdp decline years and recession end is the presence of two continuous GDP increase years

https://en.xdnf.cn/q/117871.html

Related Q&A

Inherit view and adding fields

I want to add my 2 fields boatlenght and fuelcapacity under price list in product form view but they are not showing up. What did i miss.<?xml version="1.0" encoding="utf-8"?&g…

Linux and python: Combining multiple wave files to one wave file

I am looking for a way that I can combine multiple wave files into one wave file using python and run it on linux. I dont want to use any add on other than the default shell command line and default py…

How does the in operator determine membership? [duplicate]

This question already has answers here:Set "in" operator: uses equality or identity?(5 answers)Closed 7 years ago.How does the in operator work for Python? In the example below I have two n…

Python Automatically ignore unicode string

Ive been searching to automatically import some files but since Im on Windows i got the unicode error (because of the "C:\Users\..."). Ive been looking to correct this error and found some h…

How to obtain currency rates from this website converter widget python

How can I implement the currency rates on this website and keep the currencies up to date so that i can access them in python from this website and input and output values and currencies types. I need …

Trying to add sums from a csv file in python

I need to add sums of a csv file. The program is a test for a travel reservation system and the file reads like this:availableSTART,reservations,cancellations,availableEND 20,1,0,18I need to subtract r…

Numerical patterns in Python3 [duplicate]

This question already has answers here:How to print without a newline or space(30 answers)Closed 7 years ago.Im fairly new to programming, i have to start learning it for Uni.I have to make a pattern a…

setsockopt before connect for reactor.connectTCP

I have a small python client which needs a setsockopt after create_socket, but before connect. The non-twisted python code is as follows. How can this be expressed in a twisted environment?create_sock…

Manage quotation marks in XPath (lxml)

I want to extract web elements from the table MANUFACTURING AT A GLANCE in the given website. But the name of the row has (single quote). This is interfering with my syntax. How do I overcome this iss…

exception capture in threads and parent

How do you nicely capture exceptions in Python threads?If you have a threaded python app sys.excepthook does not capture errors in children.When a child raises an exception the parent will continue to…