首页 新闻 会员 周边

请问dataframe怎么存成图片?

0
悬赏园豆:100 [待解决问题]

请问dataframe怎么存成图片?下面这个错怎么解决?

在网上找到个dataframe_image包,貌似能完美解决这个问题,但在允许时报错

df = pd.DataFrame(np.random.rand(6,4))
df_styled = df.style.background_gradient()
df_styled
import dataframe_image as dfi
dfi.export(df_styled,"df_styled.png")

报错如下:

CalledProcessError Traceback (most recent call last)
~\AppData\Local\Temp\ipykernel_11928\4137439.py in
----> 1 dfi.export(df_styled,"df_styled.png")

c:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\site-packages\dataframe_image_pandas_accessor.py in export(obj, filename, fontsize, max_rows, max_cols, table_conversion, chrome_path, dpi)
39 dpi=None,
40 ):
---> 41 return _export(obj, filename, fontsize, max_rows, max_cols, table_conversion, chrome_path, dpi)
42
43

c:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\site-packages\dataframe_image_pandas_accessor.py in _export(obj, filename, fontsize, max_rows, max_cols, table_conversion, chrome_path, dpi)
117 html = obj.to_html(max_rows=max_rows, max_cols=max_cols, notebook=True)
118
--> 119 img_str = converter(html)
120
121 try:

c:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\site-packages\dataframe_image_screenshot.py in run(self, html)
196 def run(self, html):
197 self.html = html
--> 198 img = self.take_screenshot()
199 img_str = self.finalize_image(img)
200 return img_str

c:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\site-packages\dataframe_image_screenshot.py in take_screenshot(self, ss_width, ss_height)
135 ]
136
--> 137 self.generate_image_from_html(args)
138
139 im = Image.open(temp_img)

c:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\site-packages\dataframe_image_screenshot.py in generate_image_from_html(self, args)
141
142 def generate_image_from_html(self, args):
--> 143 subprocess.run(executable=self.chrome_path, args=args, check=True)
144
145 def possibly_enlarge(self, im):

c:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\subprocess.py in run(input, capture_output, timeout, check, *popenargs, **kwargs)
510 if check and retcode:
511 raise CalledProcessError(retcode, process.args,
--> 512 output=stdout, stderr=stderr)
513 return CompletedProcess(process.args, retcode, stdout, stderr)
514

CalledProcessError: Command '['--enable-logging', '--disable-gpu', '--headless=new', '--crash-dumps-dir=/tmp', '--force-device-scale-factor=1', '--window-size=1400,900', '--hide-scrollbars', '--screenshot=C:\Users\ADMINI~1\AppData\Local\Temp\tmpyw9517vb\temp.png', 'C:\Users\ADMINI~1\AppData\Local\Temp\tmpyw9517vb\temp.html']' returned non-zero exit status 3221225477.

猪头33的主页 猪头33 | 初学一级 | 园豆:14
提问于:2023-04-06 14:44
< >
分享
所有回答(1)
0

这个错误可能是由于您的计算机缺少Chrome浏览器或Chrome驱动程序而导致的。您可以尝试以下步骤来解决这个问题:

确保您已经安装了Chrome浏览器,并且版本与您的Chrome驱动程序兼容。您可以在此处下载Chrome驱动程序:https://sites.google.com/a/chromium.org/chromedriver/downloads

将Chrome驱动程序添加到您的系统PATH环境变量中。您可以按照以下步骤操作:

a. 在Windows上,打开“控制面板” -> “系统” -> “高级系统设置” -> “环境变量”。

b. 在“系统变量”部分中,找到“Path”变量,并单击“编辑”按钮。

c. 单击“新建”按钮,将Chrome驱动程序所在的文件夹的路径添加到该变量中。

d. 单击“确定”按钮,保存更改。

确保您的Chrome浏览器和Chrome驱动程序版本相同。如果它们不兼容,您可能需要下载适合您Chrome版本的不同版本的Chrome驱动程序。

如果以上步骤无法解决问题,请尝试使用其他方式将DataFrame转换为图像。

Technologyforgood | 园豆:5633 (大侠五级) | 2023-04-06 19:44
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册