I want to remove rows where my target value is null more than 25% of the time with the 25% condition applied to another column. Alternatively I could come up with a threshold as a max count of number of times NaN is acceptable but again based on another column's value.

My goal is to impute values if there are enough observations by group based on another column and if the threshold is not met remove those observations.

My dataframe is much larger but its something like this - suppose 50% of 'a3' values corresponding to col['aid'] are null in col['T']

```
df = pd.DataFrame([[1,'a1','c1', 111],
                   [2,'a2','c3', 222],
                   [3,'a3','c3',],
                   [4,'a1','c5', 444],
                   [5,'a3','c4',],
                   [6,'a3','c5', 666],
                   [7,'a3','c3', 777]], columns=['pid','aid','cid','T'])
df
   pid aid cid      T
0    1  a1  c1  111.0
1    2  a2  c3  222.0
2    3  a3  c3    NaN
3    4  a1  c5  444.0
4    5  a3  c4    NaN
5    6  a3  c5  666.0
6    7  a3  c3  777.0

```

I've tried 

```
df.dropna(thresh=0.25*(df['aid'].value_counts()), axis = 1)

```

my desired output at threshold of 25% is

```
   pid aid cid      T
0    1  a1  c1  111.0
1    2  a2  c3  222.0
3    4  a1  c5  444.0
5    6  a3  c5  666.0
6    7  a3  c3  777.0

```

at threshold of 51% my dataframe would be unchanged

```
   pid aid cid      T
0    1  a1  c1  111.0
1    2  a2  c3  222.0
2    3  a3  c3    NaN
3    4  a1  c5  444.0
4    5  a3  c4    NaN
5    6  a3  c5  666.0
6    7  a3  c3  777.0

```

any advice would be appreciated