count pands sf code example Example: python count variable and put the count in a column of data frame df['freq'] = df.groupby('myvar')['myvar'].transform('count')