Sign up to take part
Registered users can ask their own questions, contribute to discussions, and be part of the Community!
Added on September 10, 2024 2:52AM
Likes: 0
Replies: 1
Hi,
I am trying to save a pandas styler object as an HTML ( ref: pandas.io.formats.style.Styler.to_html — pandas 2.2.2 documentation (pydata.org) ) in Dataiku Managed folder (HDFS not local). Can you help me with that?
My dataframe styler name: df
folder handler: folder
Code to save to a managed folder:
region_monitor_path = os.path.join(
"/", f"{my_styled_report}-{current_time_string}.HTML") with folder.get_writer(region_monitor_path) as writer:
writeable = df.to_html()
writer.write(writeable)
This code is giving me an error saying:
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
Cell In[22], line 3
1 with folder.get_writer(region_monitor_path) as writer:
2 writeable = df.to_html()
----> 3 writer.write(writeable)
File /datadir/dataiku/dataiku-dss-12.5.1/python/dataiku/core/managed_folder.py:81, in ManagedFolderWriter.write(self, b)
66 def write(self, b):
67 """
68 Write data to the file.
69
(...)
79 :param bytes b: the data, as byte array
80 """
---> 81 self.piping_thread.write(b)
File /datadir/dataiku/dataiku-dss-12.5.1/python/dataiku/core/dkuio.py:229, in PipeToGeneratorThread.write(self, data)
227 for chunk in self._chunked(data):
228 self._check_health()
--> 229 self.buffer.write(chunk)
230 if self.buffer.tell() >= self.chunk_size:
231 self.flush()
TypeError: a bytes-like object is required, not 'str'
Try this:
folder.upload_stream("file_name", df.to_html())