I have the following dataframe. I want to create another variable Bond that divides the Rate for Pool Collateral by Single Collateral for each country and for each year. How would you do that? For example, you would divide the rate in line 0 by the rate in line 4 or the rate in line 8 by the rate in line 7. For the countries that do not have an observation for Pool and Single Collateral, I want a missing value.
import pandas as pd
df={'Date': [2016, 2016, 2016, 2016, 2016, 2016, 2016, 2017, 2017, 2017, 2017, 2017, 2017],
'Country':['DE', 'AT','GB', 'FR', 'DE', 'FR', 'AT', 'GB', 'GB', 'DE', 'AT', 'FR' , 'AT'],
'Collateral':['Pool', 'Pool', 'Single', 'Single', 'Single', 'Pool', 'Single', 'Single', 'Pool', 'Pool', 'Pool', 'Pool', 'Single'],
'Rate': [0.2, 0.3, 0.1, 0.4, 0.6, 0.002, 0.005, 0.2, 0.9, 0.5, 0.67, 0.08, 0.4]}
df = pd.DataFrame(df)
df