f = open('read.txt','r',)
print f
cont = f.readlines()
print cont
y = np.zeros(30597 ,dtype=np.int16)
x = np.zeros(30597)
z = np.zeros(30597)
t = np.zeros(30597)
i = 0
for line in cont:
y[i], x[i], z[i], t[i] = line.split("\t")
i = i +1
f = open('writeme.txt', 'w')
for i in range(0,30597):
f.write(x)
i += 1
f.close()
我有一个txt文件我试图从python中读取它并将四列转换为数组而没有前4行(单位,x,y ..)。
稍后以其他格式导出
但我没有得到我需要的东西,请帮助一下 非常感谢你
答案 0 :(得分:0)
**我可以解决我的问题,对于另一位程序员或工程师来说,这可能是一天的解决方案**
import numpy as np
import pandas as pd
data = np.genfromtxt('Input.txt', delimiter='\t')
x1 = data[:,][3:,0]
y1 = data[:,][3:,1]
xLev1 = data [3:,][:,2]
yLev1 = data [3:,][:,3]
#export the data
x1_col = x1.reshape(-1,1)
x2_col = x2.reshape(-1,1)
xLev1_col = xLev1.reshape(-1,1)
xLev2_col = xLev2.reshape(-1,1)
#print yn_col
yLev_col1 = yLev1.reshape(-1,1)
yLev_col2 = yLev2.reshape(-1,1)
for i in range(0,len(xLev1)):
#I110_Q634
f.write(str(xLev1[i]+135.63)+";"+str((yLev1[i]-yLev1[0])*1000)+
";"+str(xLev2[i]+130.950)+";"+str((yLev2[i]-yLev2[0])*1000)+
+"\n")
f.close()