Filesystem Type 1K-blocks Used Available Use% Mounted on
/dev/sda ext4 245671 47009 181459 21% /initlo
/dev/loop7 squashfs 39552 39552 0 100% /
none tmpfs 65536 1064 64472 2% /tmp
none aufs 65536 1064 64472 2% /dev
none tmpfs 510184 24 510160 0% /dev/shm
none aufs 65536 1064 64472 2% /etc
none aufs 65536 1064 64472 2% /var
none aufs 65536 1064 64472 2% /www
none aufs 65536 1064 64472 2% /mcl
none aufs 65536 1064 64472 2% /eds
想要创建一个字典(作为表头的键和值应该根据各自的列)。请帮助创建此词典。请点击链接获取该表的图片。你知道吗
从@Rishikesh Jha(谢谢)那里得到灵感,下面是我建议的答案(不使用像pandas这样的高级库):
结果如下:
注
split_spaces
函数足够健壮,如果您有多个空格或制表符,甚至是两个空格或制表符的混合,那么它无论如何都可以工作。参见definition of ^{+
表示“一个或多个”。你知道吗在我的理解中,问题是“如何在Python字典中转换包含上述输出的字符串”?你知道吗
一种可能的解决方案是让pandas为您做步法(假设您的表在一个文件中):
诀窍在于分隔符参数(
\s+
:一个或多个空格/制表符)这是输出:
输出似乎是一个tab分隔的字符串/tab分隔的字符串列表。我会把完整的字符串改成一个字符串列表
输出:
相关问题 更多 >
编程相关推荐