I have a pandas dataframe with column “x”, “y”, and “z”. I want to group by column “x” and find the average occurrence of the value “a” in column “y” per group. Also only count the occurrences when the value in “z” is not “b”.
You can use the `groupby` method in Pandas to group by the x column and use the `mean` method to find the average of the y column per group. To only count the occurrences of a when the value in z is not b, you can create a boolean mask to filter out the rows where z is b, and then use the `sum` method to count the number of a values. Finally, divide the count by the size of each group to find the average occurrence. Here's an example:

```
df = pd.DataFrame({
    x: [1, 1, 2, 2, 3, 3],
    y: [a, b, a, a, b, a],
    z: [c, d, c, e, f, g]
})

mask = (df[y] == a) & (df[z] != b)
grouped = df.groupby(x)
result = (grouped[y][mask].sum() / grouped.size()).reset_index(name=mean_a_occurrence)
```

The resulting `result` dataframe will contain two columns: x and mean_a_occurrence. The mean_a_occurrence column will contain the average occurrence of the value a in column y per group, filtered by the condition on column z.