I have a DataFrame with multiple columns. The DataFrame is unique with respect to col_a. I want to find out the frequency of col_c against each unique value of col_b. Note that some of the values of col_a are repeated in col_b. All the columns are of the type object.
Example:
col_a col_b col_c
1234 1234 1567
1235 1234 1567
1236 1234 1987
1237 1234 1786
1321 1321 986
1322 1322 356
1323 1322 356
1354 1354 356
1364 1364 986
Output expected:
col_a col_b col_c freq_c
1234 1234 1567 2
1235 1234 1567 2
1236 1234 1987 1
1237 1234 1786 1
1321 1321 986 1
1322 1322 356 2
1323 1322 356 2
1354 1354 356 1
1364 1364 986 1
I have already found the frequency of col_c with against each unique value of col_a by using the following command:
df['freq'] = df['col_c'].map(df['col_c'].value_counts())
But it doesn't work for col_b as the df is not of the same length as col_b.
Question: How to find the frequency of col_c against each unique value of col_b?