I have a Pandas DataFrame -
>>> import numpy as np >>> import pandas as pd >>> data = pd.DataFrame(np.random.randint(low=0, high=2,size=(5,3)), ... columns=['A', 'B', 'C']) >>> data ABC 0 0 1 0 1 1 0 1 2 1 0 1 3 0 1 1 4 1 1 0
Now I use this to get the row count for column A only
>>> data.ix[:, 'A'].value_counts() 1 3 0 2 dtype: int64
What is the most efficient way to get the row count for columns A and B, for example the following output:
0 0 0 0 1 2 1 0 2 1 1 1
And finally, how can I convert it to a numpy array such as -
array([[0, 2], [2, 1]])
Please give a solution that is also consistent with
>>>> data = pd.DataFrame(np.random.randint(low=0, high=2,size=(5,2)), ... columns=['A', 'B'])
source share