crosstab output
Val Krem
valkrem at yahoo.com
Fri Jan 6 18:26:32 EST 2017
Hi all,
How do I access the rows and columns of a data frame crosstab output?
Here is code using a sample data and output.
a= pd.read_csv("cross.dat", skipinitialspace=True)
xc=pd.crosstab(a['nam'],a['x1'],margins=True)
print(xc)
x1 0 1
nam
A1 3 2
A2 1 4
I want to create a variable by adding 2/(3+2) for the first row(A1)
and 4/(1+4) for the second row (A2)
Final data frame would be
A1 3 2 0.4
A2 1 4 0.8
Thank you in advance
More information about the Python-list
mailing list