分割csv数据的python脚本

分割csv数据的python脚本,python,regex,csv,Python,Regex,Csv,我有一些csv数据如下所示: 724 "Overall evaluation: 2 Invite to interview: 2 Strength or novelty of the idea (1): 3 Strength or novelty of the idea (2): 3 Strength or novelty of the idea (3): 2 Use or provision of open data (1): 3 Use or provision of open data (

我有一些csv数据如下所示:

724 "Overall evaluation: 2
Invite to interview: 2
Strength or novelty of the idea (1): 3
Strength or novelty of the idea (2): 3
Strength or novelty of the idea (3): 2
Use or provision of open data (1): 3
Use or provision of open data (2): 3
""Open by default"" (1): 2
""Open by default"" (2): 2
Value proposition and potential scale (1): 3
Value proposition and potential scale (2): 4
Market opportunity and timing (1): 3
Market opportunity and timing (2): 4
Triple bottom line impact (1): 4
Triple bottom line impact (2): 3
Triple bottom line impact (3): 2
Knowledge and skills of the team (1): 4
Knowledge and skills of the team (2): 4
Capacity to realise the idea (1): 4
Capacity to realise the idea (2): 4
Capacity to realise the idea (3): 3
Appropriateness of the budget to realise the idea: 4"
724 "Overall evaluation: 1
Invite to interview: 1
Strength or novelty of the idea (1): 2
Strength or novelty of the idea (2): 2
Strength or novelty of the idea (3): 3
Use or provision of open data (1): 2
Use or provision of open data (2): 2
""Open by default"" (1): 3
""Open by default"" (2): 3
Value proposition and potential scale (1): 2
Value proposition and potential scale (2): 2
Market opportunity and timing (1): 2
Market opportunity and timing (2): 2
Triple bottom line impact (1): 2
Triple bottom line impact (2): 2
Triple bottom line impact (3): 1
Knowledge and skills of the team (1): 4
Knowledge and skills of the team (2): 2
Capacity to realise the idea (1): 2
Capacity to realise the idea (2): 2
Capacity to realise the idea (3): 1
Appropriateness of the budget to realise the idea: 3"
f=open("1.txt",'r').read().splitlines()
head='0'
body=[]
for x in f:
    if x=="\n" or x.strip()=='':
        continue
    try:
        int(x[0])
        print(head +':'+'+'.join(body))
        tmp=x.split()
        head=tmp[0]+'-'+tmp[1]
        body=[tmp[4]]
    except ValueError as e:
        body.append(x.split(':')[1].strip().strip('\"'))
print(head +':'+'+'.join(body))
使用python和正则表达式,是否可以识别单词
“总体评估:
的每个实例,并记录该数字,在本例中为
724
,以及
“总体评估:
”后面的值,即
2
,这样我们就剩下了:

724, 2
724, 1
比如说

如果是,如何实现这种逻辑

我试着这样做:

724 "Overall evaluation: 2
Invite to interview: 2
Strength or novelty of the idea (1): 3
Strength or novelty of the idea (2): 3
Strength or novelty of the idea (3): 2
Use or provision of open data (1): 3
Use or provision of open data (2): 3
""Open by default"" (1): 2
""Open by default"" (2): 2
Value proposition and potential scale (1): 3
Value proposition and potential scale (2): 4
Market opportunity and timing (1): 3
Market opportunity and timing (2): 4
Triple bottom line impact (1): 4
Triple bottom line impact (2): 3
Triple bottom line impact (3): 2
Knowledge and skills of the team (1): 4
Knowledge and skills of the team (2): 4
Capacity to realise the idea (1): 4
Capacity to realise the idea (2): 4
Capacity to realise the idea (3): 3
Appropriateness of the budget to realise the idea: 4"
724 "Overall evaluation: 1
Invite to interview: 1
Strength or novelty of the idea (1): 2
Strength or novelty of the idea (2): 2
Strength or novelty of the idea (3): 3
Use or provision of open data (1): 2
Use or provision of open data (2): 2
""Open by default"" (1): 3
""Open by default"" (2): 3
Value proposition and potential scale (1): 2
Value proposition and potential scale (2): 2
Market opportunity and timing (1): 2
Market opportunity and timing (2): 2
Triple bottom line impact (1): 2
Triple bottom line impact (2): 2
Triple bottom line impact (3): 1
Knowledge and skills of the team (1): 4
Knowledge and skills of the team (2): 2
Capacity to realise the idea (1): 2
Capacity to realise the idea (2): 2
Capacity to realise the idea (3): 1
Appropriateness of the budget to realise the idea: 3"
f=open("1.txt",'r').read().splitlines()
head='0'
body=[]
for x in f:
    if x=="\n" or x.strip()=='':
        continue
    try:
        int(x[0])
        print(head +':'+'+'.join(body))
        tmp=x.split()
        head=tmp[0]+'-'+tmp[1]
        body=[tmp[4]]
    except ValueError as e:
        body.append(x.split(':')[1].strip().strip('\"'))
print(head +':'+'+'.join(body))

但它不起作用:/

应该起作用的是:

lines=open("1.txt",'r').read().splitlines()
for l in lines:
    data = l.split(' "Overall evaluation: ')
    if len(data) == 2:
        print(data[0] + ", " + data[1])

split函数使用字符串
“总体评估:
作为分隔符

我将使用“总体评估:”,包括空格进行拆分。。。但答案很好。@user2177047已修复