https://prefect.io logo
Title
j

Jonas Hanfland

08/31/2020, 3:00 PM
Hello guys, I'm trying to map over pandas dataframe groups, but I can't quite get it to work even though I am able to iterate over it in a python for-loop just fine. This is what I'm trying to do:
some_task.map(df.groupby("id"))
But it gives me:
KeyError: 'Column not found: 0'
Does anyone know if mapping over groups is supported and if yes, how? Thanks in advance
c

Chris White

08/31/2020, 3:07 PM
Hi Jonas, mapping over pandas dataframes is not currently supported - mapped objects must be list-like (e.g., indexed by position); if you can convert your groupby object into a list then you should be good!
👍 1
j

Jonas Hanfland

08/31/2020, 3:19 PM
Amazing, works like a charm. Thank you very much!
e

emre

08/31/2020, 3:20 PM
^, use
list(df.groupby("id"))
instead. Even better, have a task return
list(df.groupby("id"))
, and map over the output of said task.