human
Give me a the Python code you requested given the following:
I am working on the file "Reciprocity Analysis Data Cleaning.ipynb".
The first task is:
Fisher Test Data:
<span style="color:red">NOTE: There are no libraries in python that currently support Fisher tests for tables larger than 2x2 - need to use R instead. </span>
Build and Export Contingency Tables for fisher testing in R:
Can you write Python code for it?
assistant
#Here is the Python code you requested.

behaviors = list(set(combined['Description']))

#will make the count table for number of participants that exhibit a behavior with an agent (behavior x agent) 
agents = ['jibo', 'alexa', 'computer']
def makeContingencyTable(df):
    
    table = []
    for agent in agents: 
        agentCounts = pd.DataFrame(columns = [agent])
        labels = pd.DataFrame(columns = ['Description'])
        for i in range(len(behaviors)): 
            agentDf = df[df['Agent'] == agent]
            behaviorDf = agentDf[agentDf['Description'] == behaviors[i]]  
            numParticipants = len(set(behaviorDf['Participant']))
            agentCounts.loc[i] = [numParticipants]
            labels.loc[i] = [behaviors[i]]
        table.append(agentCounts)
        
    table.append(labels)
        
    combo = pd.concat(table, axis = 1)
    combo = combo[['Description', 'jibo', 'alexa', 'computer']]
    return combo

#use this code to make contigency table based on behavior frequency and not particiants (behavior x agent) 
# def makeContingencyTable(df):
#     data = df[['Description', 'Agent']]
#     table = sm.stats.Table.from_data(data)
#     contingencyTable = table.table_orig
#     return contingencyTable

#Run these to get the complement for behavior counts 
#calculate the total number of interactions per agent 
# alexaTotal = len(combined[combined['Agent'] == 'alexa'])
# jiboTotal = len(combined[combined['Agent'] == 'jibo'])
# computerTotal = len(combined[combined['Agent'] == 'computer'])
# jiboComplement = general['jibo'].apply(lambda x: jiboTotal - x)
# alexaComplement = general['alexa'].apply(lambda x: alexaTotal - x)
# computerComplement = general['computer'].apply(lambda x: computerTotal - x)