如果我想从CLI输出创建dataframe,但不知道其中的列键,
我只知道键结束的原始位置(从原始数字0开始)和键之间的分隔符(\s+
)。你知道吗
在这种情况下,有没有快速而好的方法从输出中找到(生成)dataframe的列键?你知道吗
例如:
MODIFIED
CORE SERVER ACTIVE PASSIVE PACKAGES
------------------ ------------------------------ ----------------------------- --------
cs010 1.9.2.0-2+auto166 1.9.2.0-2+auto146 no
它应该生成以下键列表:CORE SERVER , ACTIVE , PASSIVE , MODIFIED PACKAGES
假设我理解正确,您可以拆分包含所有列名的字符串输入(用空格分隔),然后使用列表理解构建一个字典,然后从中生成一个空数据帧。你知道吗
正则表达式拆分的文档在这里:re.split()如果您想使用正则表达式。你知道吗
因为您有行输出,可以在行中加倍,但似乎有连字号指示列大小,您可以使用类似于:
这段代码不是有史以来最有效的东西,但可以完成任务,不需要添加许多函数。你知道吗
好的。你知道吗
我创建了自己的函数来生成它,并且它可以工作。你知道吗
相关问题 更多 >
编程相关推荐