我正在使用 python33 并想从包含单词和数字的文本文件中获取一串数字(下面复制/粘贴的 txt 文件中的第 30 行)。捕获所需的数字后,我想使用一个等式(即(number-30)/2)转换它们,然后找到它们的平均值并将其写入一个新文件(例如 Scope22.txt 或 csv)。我有许多单独的文件,这是第一个必须进行类似处理的文件,每个平均值都将写入同一个文件(Scope22.txt 或 csv)。附件包含关注的数量(0.0, 66.0, 70.0, 0.0, 0.0, 81.0, 64.0, 0.0, 76.0)......转换它们((number-30)/ 2)然后找到它们的平均值。
我衷心感谢您的帮助。
我的.txt:
次要类型范围 有效时间 201012132300 范围 536 西塔 48 身份证坐 名称 站点 拉特中心 23.45459 伦敦中心 -22.766379 分辨率1 1.0 分辨率1 1.0 高度 1 11.0 高度3 600.0 数据索引 输入文件类型 AAA,0,1,PPTOA 次要产品参数 SCOPe,,BBBBBBB,KKKKK_LIST_SIT,0,0,1,1 TableLabels_Locations ID 名称 有效纬度经度范围 Theta BBN Yyy TableStart_SiteLocations "LLL", "QQQQ_WWWWW", 1, 23.45459,-22.766379, 536.11,48.14, 55,22; TableEnd_SiteLocations TableLabels_TableInfoSites ID Lat Lon Range Theta BMHT PNTVlU Min Max Avg Median P95 AbsDev Var Sd Skew Curt TableStart_TableInfoSites LLL, 23.45459,-22.766379, 536.11,48.14, -1.00, 0.00, 0.00, 81.00, 39.67, 64.00, 0.00, 35.26,1.44e+03, 37.96, -0.14, -2.13; TableEnd_TableInfoSites TableLabels_TableDis Dis M TableStart_TableDis LLL, 4,200,190,180,170,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,1,0,1,0,0,0,1,0,0,0,0,0,1,0, 0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,; TableEnd_TableDis TableLabels_TableData 值_M TableStart_TableData LLL, 0.0, 66.0, 70.0, 0.0, 0.0, 81.0, 64.0, 0.0, 76.0,; TableEnd_TableData
这是我的代码:
STATS11_filename='C:/Python33/STATS11.txt'
STATS11_filename=open(STATS11_filename,'r')
line=STATS11_filename.readline()
line=STATS11_filename.readline()
line=STATS11_filename.readline()
line=STATS11_filename.readline()
line=STATS11_filename.readline()
line=STATS11_filename.readline()
line=STATS11_filename.readline()
line=STATS11_filename.readline()
line=STATS11_filename.readline()
line=STATS11_filename.readline()
line=STATS11_filename.readline()
line=STATS11_filename.readline()
line=STATS11_filename.readline()
line=STATS11_filename.readline()
line=STATS11_filename.readline()
line=STATS11_filename.readline()
line=STATS11_filename.readline()
line=STATS11_filename.readline()
line=STATS11_filename.readline()
line=STATS11_filename.readline()
line=STATS11_filename.readline()
line=STATS11_filename.readline()
line=STATS11_filename.readline()
line=STATS11_filename.readline()
line=STATS11_filename.readline()
line=STATS11_filename.readline()
line=STATS11_filename.readline()
line=STATS11_filename.readline()
line=STATS11_filename.readline()
b=line=STATS11_filename.readline()
d=(str(b[7:-3]))
print(len(b[7:-3]))
STATS11_filename.close()
a=7
Scope22_filename='C:/Python33/Scope22.txt'
Scope22_filename=open(Scope22_filename,'w')
for i in range (len(b[7:-3])):
if (b[a])>='64' or (b[a])<='254':
Scope22_filename.write(b[a])
if a==53:
quit
else:
a=a+2
Scope22_filename.close()