I am tryin to make a field structure but I am having problems while using the for loop with 3 entries in a.items().
dirs = df_vol_erp.groupby(['country', 'primary_volcano_type'])['volcano_name_x'].apply(list)
#for pais, (tipos, nombres) in dirs.items():
for pais, tipos, nombres in dirs.items():
path_pais = os.path.join(new_path, str(pais))
if not os.path.exists(path_pais):
os.makedirs(os.path.join(path_pais), exist_ok=True)
for tipo in tipos:
path_tipos = os.path.join(path_pais, str(tipo))
if not os.path.exists(path_tipos):
os.makedirs(os.path.join(path_tipos), exist_ok=True)
for nombre in nombres:
path_nombre = os.path.join(path_tipos, str(nombre))
if not os.path.exists(path_nombre):
os.makedirs(os.path.join(path_nombre), exist_ok=True)
I have this code and when run it i get ValueError: not enough values to unpack (expected 2, got 1). I also tried:
for pais, values in dirs.items(): tipos, nombres = values What can I do?
Assign two variables, then in the loop body you can split the second variable into two more variables.
for pais, value in dirs.items():
tipos, nombres = value
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.