Writing multiple files into a folder
Ksawery
Registered Posts: 2 ✭✭✭
Hi,
I would like to write multiple files into a Dataiku folder. Unfortunately, when I do the following, I am getting an error:
The truth value of a DataFrame is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
The error that I am getting is:
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)
Is there any workaround?
Answers
-
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())