Finding the maximum number of id's among all weeks available this is a really short code, but I'm trying to improve my Python skills. I've got a DataFrame, with a week variable, for every week I want to know the number of different id's in that week, and then get the maximum number of id's among all weeks. I achieve that doing this:

listt=[]
for i in range(df.week.max()):
    listt.append(df[df.week==i].id.nunique())
np.array(listt).max()


It feels to me that this can probably be done in a one-liner. How would you do it? Thanks
Instead of iterating through each possible week and filtering your dataframe, you should use df.groupby and work from there using convenience methods on the results:

df.groupby('week').id.nunique().max()