I address here only the "pythonic" part for carrying a test for a pair of values. Note however, that if the python implementation is indeed the main issue here, the question is more appropriate for the Stackexchange rather than the statistics community. Or perhaps it has to be split into parts which are properly programming and those which are statistics.
Here is an example of carrying the test for any pair of values in the table above:
#!/usr/bin/python3.6
from __future__ import division #importing non-integer division
import numpy as np #importing basic python math library
from scipy.stats import binomtest #importing binomial test
#first example
k = 98; n=100
res = binomtest(k, n, p=0.5, alternative='two-sided')
print(res.pvalue)
#second example
k=10; n=100
res = binomtest(k, n, p=0.5, alternative='two-sided')
print(res.pvalue)
p=0.5, alternative='two-sided'
are default values, so they need not necessarily be explicitly spelled here (p=0.5
reflects our null hypothesis that the gender ratio is 50/50). One could also import all the data table as, e.g., a pandas dataframe and loop over it to test all the pairs. res
object contains the final statistic, p-value, etc.
There are also similar statistical functions for carrying other tests, including chi-squared - e.g., this one (this is not necessarily what you have to use, as there are many chi-squared capacities in scipy, which can be found by searching in scipy web-page or simply googling.)