Вы можете создать уникальный список для всех значений в столбце с помощью list(df['type of use'].unique())
и выполнять итерации, как показано ниже:
for i in list(df['type of use'].unique()):
print(df[df['type of use'] == i].sample(frac=0.2))
или
i = 0
while i < len(list(df['type of use'].unique())):
df1 = df[(df['type of use']==list(df['type of use'].unique())[i])].sample(frac=0.2)
print(df1.head())
i = i + 1
Для хранения вы можете создать словарь:
dfs = ['df' + str(x) for x in list(df2['type of use'].unique())]
dicdf = dict()
i = 0
while i < len(dfs):
dicdf[dfs[i]] = df[(df['type of use']==list(df2['type of use'].unique())[i])].sample(frac=0.2)
i = i + 1
print(dicdf)
Будет напечатан словарь данных.
Вы можете распечатать то, что хотите увидеть, например, для образца жилья: print (dicdf['dfhousing'])