count number of columns in dataframe padnas code example
Example 1: number of column in dataset pandas
len(df.columns)
Example 2: python count variable and put the count in a column of data frame
df['freq'] = df.groupby('myvar')['myvar'].transform('count')