Question: plz give me the right answer and python code of this questionthx this is the filepresident.csv and this is the filesp500_daily.csv Many U.S. presidents have

plz give me the right answer and python code of this questionthx
 plz give me the right answer and python code of this
questionthx this is the filepresident.csv and this is the filesp500_daily.csv Many U.S.
this is the filepresident.csv
presidents have attempted to take credit for the strong performance of the
economy or stock market, and political commentators often remark that one party's
and this is the filesp500_daily.csv
policies are more favorable for economic growth. In this exercise, your task
is to make a time series plot of the quarterly returns of

Many U.S. presidents have attempted to take credit for the strong performance of the economy or stock market, and political commentators often remark that one party's policies are more favorable for economic growth. In this exercise, your task is to make a time series plot of the quarterly returns of the S&P 500 stock market index and shade the plot background based on the president's party affiliation blue for Democrats, red for Republicans The file "presidents.csv contains data on the U.S. presidents since 1950, including their name, the start and end dates of their administration, and their political party affililation. The file "SP500_ daily.cs contains data on the daily performance of the S&P 500 stock market index since January 3, 1950 Part (a): 1. Import "presidents.csv into a Pandas dataframe. Set the president's name as the index, and convert the start and end dates to datetime objects 2 Import "SP500_daily.csv" into a Pandas dataframe. Convert the column names to lower case, convert the date variable to a datetime object, and set the date as the index 3 Change the frequency of the stock data from daily to quarterly, using the mean() method 4 Create a new column in the stock data that contains the quarterty growth rate (e., return) of the S&P 500 in percent. Use the close' column to compute the return 5. Plot the quarterty returns of the S&P 500 over time as a solid black line. Set the figure size to (11,5) Add a horizontal dashed line at y 0. Set the limits of the horizontal axis to April 12, 1945 and January 20, 2021. Label the vertical axis as "Percent return" and btle the plot "Quarterty returns of the s&p 300 by presidential party". Finally, remove the borders from the top and right sides of the figure 6 Now all you need to do is shade the time period of each administration with the appropriate color. To do so, you should use a for-loop to loop through each president and use the function ax.axvspan() to shade the appropriate time period Again, use blue for Democrats and red for Republicans, and set the alpha composite to 0.4 7. Not required, but fun and challenging: Make a legend describing the shading scheme, and make sure that each party appears only once in the legend In [ ]

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!