python行列转换脚本编写
来源:互联网 发布:广州商陆花软件多少钱 编辑:程序博客网 时间:2024/06/05 06:41
python行列转换脚本编写
一、
table=[(‘Person’,’Disks’,’Books’),
(‘Zoe’,’12’,’24’),
(‘John’,’17’,’5’),
(‘Jul’,’3’,’11’)]
命令:
print zip(*table)
输出:
[(‘Person’,’Zoe’,’John’,’Jul’),
(‘Disks’,’12’,’17’,’3’),
(‘Books’,’24’,’5’,’11’)]
二、
现在有两行数据如下:
python]# cat lianxi.bac
a b c d e f g h 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
a b c d e f g h 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
要求前8列不变,后面每两列为一组。行转为列。
eg.
a b c d e f g h 1 2
a b c d e f g h 3 4
···
a b c d e f g h 39 40
脚本如下:
#!/usr/bin/env Python
# -- conding:utf-8 --
# file:lianxi.py
#
import sys
import repath=’/lianxi/python/lianxi.bac’
file=open(path,’r’)ou=[]
for i in range(8,47):
if i%2 == 0:
ou.append(i)for line in file:
for n in ou:
item=line.split()[0:8]
a=line.split()[n:n+2]
item += a
# print (item)
print ’ ‘.join(item)
执行结果:
python]# python 4.py
a b c d e f g h 1 2
a b c d e f g h 3 4
a b c d e f g h 5 6
a b c d e f g h 7 8
a b c d e f g h 9 10
a b c d e f g h 11 12
a b c d e f g h 13 14
a b c d e f g h 15 16
a b c d e f g h 17 18
a b c d e f g h 19 20
a b c d e f g h 21 22
a b c d e f g h 23 24
a b c d e f g h 25 26
a b c d e f g h 27 28
a b c d e f g h 29 30
a b c d e f g h 31 32
a b c d e f g h 33 34
a b c d e f g h 35 36
a b c d e f g h 37 38
a b c d e f g h 39 40
a b c d e f g h 1 2
a b c d e f g h 3 4
a b c d e f g h 5 6
a b c d e f g h 7 8
a b c d e f g h 9 10
a b c d e f g h 11 12
a b c d e f g h 13 14
a b c d e f g h 15 16
a b c d e f g h 17 18
a b c d e f g h 19 20
a b c d e f g h 21 22
a b c d e f g h 23 24
a b c d e f g h 25 26
a b c d e f g h 27 28
a b c d e f g h 29 30
a b c d e f g h 31 32
a b c d e f g h 33 34
a b c d e f g h 35 36
a b c d e f g h 37 38
a b c d e f g h 39 40
- python行列转换脚本编写
- python行列转换
- [python笔记]行列转换,数据透视
- python脚本编写
- python setup脚本编写
- python 编写 cgi 脚本
- SQL+SERVER+2005%2B+版本行列转换数据脚本
- 行列转换
- 行列转换
- 行列转换
- 行列转换
- 行列转换
- 行列转换
- 行列转换
- 行列转换
- 行列转换
- 行列转换
- 行列转换
- Python 元组
- 初始化 XML 解析器代码一览
- C# via CLR 多线程的学习
- Linux那些事(6)-Linux用户和用户组管理
- web前端关于百度地图反地理编码的问题
- python行列转换脚本编写
- HTTP权威指南总结
- C++ vector用法
- DOM 是什么?以及XML 解析
- Java8的一些新特性 java.util.function包
- 周志华《机器学习》——学习笔记
- 怎么写robots文件?robots文件有什么用?
- JAVA中,JSONObject和JSONArray的遍历
- springMVC学习之JSTL与URL相关的行为