- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个像这样的 pandas 数据框
>>> df
Out[126]:
score id
0 0.999989 654153
1 0.992971 941351
2 0.979518 701608
3 0.972667 564000
4 0.936928 999843
并且想要转换为漂亮(以便写入具有更好可读性的文本文件)
import prettytable as pt
x = pt.PrettyTable()
for col in list(df.columns):
x.add_column(col,df[col])
然后在函数内,我使用
print(x.get_string())
并收到此错误
File "<ipython-input-130-8db747160a67>", line 5, in <module>
verbose = True)
File "<ipython-input-129-4e27c067e0b5>", line 104, in lda_save_eval
print(x.get_string())
File "C:\Users\USER\Anaconda3\envs\tensorflow\lib\site-packages\prettytable.py", line 990, in get_string
self._compute_widths(formatted_rows, options)
File "C:\Users\USER\Anaconda3\envs\tensorflow\lib\site-packages\prettytable.py", line 894, in _compute_widths
widths = [_get_size(field)[0] for field in self._field_names]
File "C:\Users\USER\Anaconda3\envs\tensorflow\lib\site-packages\prettytable.py", line 894, in <listcomp>
widths = [_get_size(field)[0] for field in self._field_names]
File "C:\Users\USER\Anaconda3\envs\tensorflow\lib\site-packages\prettytable.py", line 77, in _get_size
lines = text.split("\n")
AttributeError: 'int' object has no attribute 'split'
有什么线索吗?
最佳答案
尝试使用 print (x.get_string())
而不是 print(x.get_string)
为了改进,试试这个,为了以更好的可读性写入文本文件,您不需要循环使用 tabulate
它为您提供了更多灵 active 。
试试这个,
from tabulate import tabulate
print (tabulate(df,df.columns,tablefmt='psql'))
在tablefmt
中,您可以提供许多选项来获得不同的样式。有关更多详细信息,请参阅此 link
关于Python 漂亮的 get_string 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51018046/
关闭。此题需要details or clarity 。目前不接受答案。 想要改进这个问题吗?通过 editing this post 添加详细信息并澄清问题. 已关闭 3 年前。 Improve th
我有一个像这样的 pandas 数据框 >>> df Out[126]: score id 0 0.999989 654153 1 0.992971 9413
经过在 Windows Vscode 上的多次试验,我终于让 cs50 库正常工作了。现在的问题是 get_string 函数无法按如下方式工作: int main(void) { strin
关闭。这个问题是not reproducible or was caused by typos .它目前不接受答案。 这个问题是由于错别字或无法再重现的问题引起的。虽然类似的问题可能是on-topi
以下代码是应用程序的一小部分。对于该应用程序,我需要使用 in_box.get_string()。 in_box的声明和定义在this中GUI.h 和 GUI.cpp 文件中的地址。 对于整数,它工作
我无法获取 USB 设备的字符串描述符。我正在寻找的是人性化的制造商和产品名称。我使用 libusb-1.0 作为后端,并且能够使用提供的 libusb 测试程序获取制造商名称,所以我知道它存在。 P
我正在尝试对我的第一个 Realm 数据库进行简单查询。我在尝试访问由我的查询方法返回的对象的属性时遇到错误。我有两个问题: 1.这个错误是什么意思?我很难理解它... 2. 我查询的方式正确吗?如果
我正在使用 json-spirit为我的 ws++ 解析 json服务器。 我正在比较字符串以验证注册过程、确认登录、电子邮件、密码等。 json-spirit 的 get_str() 返回 cons
我是一名优秀的程序员,十分优秀!