[Solved] How to loop over an array of variables with the same form of name? [closed]


If you want to do all the columns in your dataframe:

for col in df.columns:
    sns.countplot(df[col])

. Otherwise, following the pattern in your question:

for i in range(1,11):
    column='id_'+"{0}".format(i).zfill(2)
    sns.countplot(df[column])

that will go through the numbers 1-10 and set column to the correct column name. zfill will make sure that for single digit numbers, column equals id_01 rather than id_1.

solved How to loop over an array of variables with the same form of name? [closed]