I have a pandas dataframe df with this settings
col1 col2
v1 i1
v1 i50
v2 i60
v2 i1
v2 i8
v10 i8
v10 i1
v10 i2
..
I would like to compute how many elments of col1 has a value of col2. And store the results into a dataframe with this setting
col1 frequency
i1 80
i2 195
... ...
I tried to do this in pandas,
item_frequency = pd.unique(relevant_data[relevant_data['col2'].isin(pd.unique(relevant_data['col2'].values.ravel()))]['col1'].values.ravel())
which is yielding the error
raise ValueError('Lengths must match to compare')
ValueError: Lengths must match to compare
PS: I'd like to do this in a vectorized manner.