Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
329 views
in Technique[技术] by (71.8m points)

python - 从空格分隔的csv中提取特定数据(Extracting specific data from a whitespace separated csv [closed])

I need a script to extract data from multiple whitespace separated csv's.

(我需要一个脚本来从多个空格分隔的csv中提取数据。)

Following is the data that is there in each csv:

(以下是每个csv中的数据:)

H   156898900   0         50K     0 6 -1 WIN002862      1   Hondrus JHUHUGHJHHHHHHHH :18:08ytrvhNN :12B:
## $$$$ :18:9ynnnhNN :12B:     98uu    WIN00876   1   Hondrus

Output Needed, two columns in a dataframe, ID & MID:

(需要输出,数据帧中的两列,ID和MID:)

[ID            MID
08ytrvhNN     002862
9ynnnhNN      00876][1]

Using the below code which is not working---

(使用以下无效的代码-)

import glob
files = glob.glob('*.csv')
strings = []
for file in files:
  with open(file, "r", encoding='UTF-8') as fobj:
      text = fobj.read()
  import re
  a = re.compile(':18:(.*) :12N:')
  b=re.compile('WIN(.*)Hondrus')
  z = a.findall(text)
  k=b.findall(text)
  strings.append(z[0] + "," + k[0])
  ask by Ryan translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...