-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathABAB_adv.py
38 lines (31 loc) · 1.12 KB
/
ABAB_adv.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# -*- coding: utf-8 -*-
"""
File Name: ABAB_adv.py
Description: 整理ABAB型副词
Author: Rabbear Su
creation date: 2019/5/23
"""
import pandas as pd
import os
txt_path = 'data\\ABAB.txt'
with open(txt_path, 'r') as f:
lines = f.readlines()
f.close()
df = pd.DataFrame(columns=['副词', '意思', '例句', '例句意思'])
for i, line in enumerate(lines):
index = int(i / 2)
line = line.strip('\r\n').replace(u'\u3000', u'')
if i % 2 == 0:
try:
df = df.append({'副词': line.split('?')[0], '意思': line.split('?')[1], '例句': '', '例句意思': ''},
ignore_index=True)
except:
df = df.append({'副词': line.split(' ')[0], '意思': line.split(' ')[1], '例句': '', '例句意思': ''},
ignore_index=True)
if i % 2 != 0:
try:
df.iloc[index]['例句'] = line.split('/')[0].split(':')[1]
df.iloc[index]['例句意思'] = line.split('/')[1]
except:
df.iloc[index]['例句'] = line.split(':')[1]
df.to_excel('output\\ABAB.xlsx')