如何从树点文件制作表格?
如何从树点文件制作表格?
例如:点文件中的这一行:
0 [label="TV <= -0.239\nmse = 25.8\nsamples = 160\nvalue = 14.218"] ;
1 [label="TV <= -1.422\nmse = 7.824\nsamples = 66\nvalue = 10.015"] ;
0 -> 1 [labeldistance=2.5, labelangle=45, headlabel="True"] ;
2 [label="radio <= 0.549\nmse = 2.58\nsamples = 19\nvalue = 6.805"] ;
1 -> 2 ;
所以表:
0,TV,-0.239
1,TV,-1.422
2,radio,0.549
.
.
.
我如何在Python中制作这个表?
how to make a table from a tree dot file??
for example: this lines from dot file :
0 [label="TV <= -0.239\nmse = 25.8\nsamples = 160\nvalue = 14.218"] ;
1 [label="TV <= -1.422\nmse = 7.824\nsamples = 66\nvalue = 10.015"] ;
0 -> 1 [labeldistance=2.5, labelangle=45, headlabel="True"] ;
2 [label="radio <= 0.549\nmse = 2.58\nsamples = 19\nvalue = 6.805"] ;
1 -> 2 ;
so the table:
0,TV,-0.239
1,TV,-1.422
2,radio,0.549
.
.
.
how can I make this table in python??
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您想使用自己的代码执行此操作,则应用正则表达式来分离文件的每一行非常简单。下面是一个为您的输入提供所需结果的示例:
结果:
我不熟悉这种文件格式,因此我不知道您是否需要比此表达式更复杂的表达式来处理所有可能的有效输入。如果上述表达式不适用于您想要映射到结果表的所有可能的行,您应该能够调整表达式以获得您想要的行为。
如果有一个包可以为您执行此操作,这样您就不必了解文件格式的详细信息,那么使用它显然是一个更干净的解决方案。我不熟悉这个特定的问题领域,所以我不会告诉你这样的事情是否可能存在。
If you're looking to do this with your own code, applying a regular expression to pick apart each line of the file is straightforward. Here's an example that gives the desired result for your input:
Result:
I'm not familiar with this file format, so I don't know if you'd need a more sophisticated expression than this one to handle all possible valid inputs. If the above expression doesn't work for all possible lines that you want to map to the resulting table, you should be able to tweak the expression to get the behavior you desire.
If there is a package that will do this for you so that you don't have to understand the details of the file format, using that would obviously be a cleaner solution. I'm not familiar with this particular problem domain, so I'm not one to tell you if such a thing might exist.