【发布时间】:2019-09-12 22:59:25
【问题描述】:
祝大家今天好!
问题是我有一些 txt 文件,并且我有将它们放在一起的脚本。每个txt文件都从:
Export Type: by LAI\GCI\SAI
LAI\GCI\SAI: fjdfkj
HLR NUMBER: NA
Routing Category: NA
Telephone Service: NA
Export User Scope: Attached & Detached User
Task Name: lfl;sfd
Data Type: col1/col2
Begin Time of Exporting data: 2019-4-14 19:41
=================================
col1 col2
401885464645645 54634565754
401884645645564 54545454564
401087465836453 54545454565
401885645656567 53434343435
401084569498484 54342340788
401088465836453 56767686334
401439569345656 64545467558
401012993933334 55645342352
401034545566463 34353463464
我想从 col1 和 col2 开始组合(没有列的名称),但脚本也将它们与开头的单词组合起来。 你能更新这个脚本吗?
import fileinput
import glob
file_list = glob.glob("*.txt")
with open('resultfile.txt', 'w') as file:
input_lines = fileinput.input(file_list)
file.writelines(input_lines)
另一个问题是我想去掉 col2 中值开头的 5 并删除所有不从 40108/40188/401088e 开始的行。谢谢!
【问题讨论】:
-
请告诉我们您尝试了什么,以及您遇到的问题。
-
我不知道如何在我要合并的每个 txt 文件中对前 10 行进行 scip。请你更新上面的这个脚本好吗?
-
请更新问题标题以反映您遇到的具体问题。阅读minimal reproducible example 会对您有所帮助。这将有助于将您的问题摆在能够提供答案的人面前。
标签: excel python-3.x pandas data-science