[USER (data scientist)]: Great! Now, can you calculate the surface performance of Raonic M. against each of Federer's opponents? Please define a function to calculate the overall win rate, head-to-head (h2h) record, and performance on different surface types for a specified player against a specific opponent in the ATP tennis dataset.

[YOU (AI assistant)]: Sure, let's modify the existing function to include surface performance calculation: 
'''
import pandas as pd
import numpy as np
import pickle

atp_tennis = pd.read_csv('atp_tennis.csv')

def calculate_win_rate(player, opponent, data):   
    player_matches = data[((data['Player_1'] == player) & (data['Player_2'] == opponent)) | ((data['Player_1'] == opponent) & (data['Player_2'] == player))]   
    total_matches = len(player_matches)   
    wins = len(player_matches[player_matches['Winner'] == player])   
    win_rate = wins / total_matches if total_matches > 0 else 0   

    return win_rate   
'''

[USER (data scientist)]: Cool! Now, I'd like to calculate the win rate of Raonic M. against each of Federer's opponents. Can you help me with that? Please define a function to calculate the win rate of a specified player against a specific opponent in the ATP tennis dataset.

[YOU (AI assistant)]: Sure, let's define a function to calculate the win rate of Raonic M. against a given opponent: 
'''
import pandas as pd
import numpy as np
import pickle

atp_tennis = pd.read_csv('atp_tennis.csv')

def calculate_win_rate_and_h2h(player, opponent, data):   
    player_matches = data[((data['Player_1'] == player) & (data['Player_2'] == opponent)) | ((data['Player_1'] == opponent) & (data['Player_2'] == player))]   
    total_matches = len(player_matches)   
    wins = len(player_matches[player_matches['Winner'] == player])   
    win_rate = wins / total_matches if total_matches > 0 else 0   
    h2h_record = wins / total_matches if total_matches > 0 else 0   

    return win_rate, h2h_record 

'''

[USER (data scientist)]: That's a nice function! Can you also calculate the head-to-head record of Raonic M. against each of Federer's opponents? Please define a function to calculate both the win rate and the head-to-head (h2h) record of a specified player against a specific opponent in the ATP tennis dataset. 
My template of code snippet is:

---BEGIN CODE TEMPLATE---

import pandas as pd
import numpy as np
import pickle

atp_tennis = pd.read_csv('atp_tennis.csv')

# YOUR SOLUTION BEGIN:
<code1>
[COMPLETE YOUR CODE] 
</code1>
# YOUR SOLUTION END

---END CODE TEMPLATE---

[YOU (AI assistant)]: Sure, let's add the head-to-head record calculation to the existing function: 
'''
import pandas as pd
import numpy as np
import pickle

atp_tennis = pd.read_csv('atp_tennis.csv')

# YOUR SOLUTION BEGIN:
