Sign up to take part
Registered users can ask their own questions, contribute to discussions, and be part of the Community!
Registered users can ask their own questions, contribute to discussions, and be part of the Community!
Hi,
I would like to write multiple files into a Dataiku folder. Unfortunately, when I do the following, I am getting an error:
data_df = dataiku.Dataset("data")
data = data.get_dataframe()
output = dataiku.Folder("2jiawe32x")
for cnt in data.country.unique():
df = data[data.country == cnt]
output.upload_stream(str(cnt), df)
The error that I am getting is:
The truth value of a DataFrame is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
Is there any workaround?
This happens because you should not directly pass the pandas dataframe as the second argument to the upload_stream method:
https://doc.dataiku.com/dss/latest/python-api/managed_folders.html#dataiku.Folder.upload_stream
Thus, you could do something like:
for cnt in data.country.unique():
df = data[data.country == cnt]
output.upload_stream(str(cnt) + ".csv", df.to_csv())