我正在尝试将字符串列表列表写入.csv文件,由于某种原因,它只起省略号的前几个元素(有时会格式化打印方式)。我不确定这是否与nltk.corpus.reader
或CHILDESCorpusReader
有关,或者是否有某种方法可以编辑我向文件中写入内容的方式。下面是文件本身的代码和屏幕截图。非常感谢您的任何想法!
import os
import os.path
import nltk
import csv
from nltk.corpus.reader import CHILDESCorpusReader
corpus_root = nltk.data.find('/Users/home/Desktop/Childes')
with open('child_speech_test.csv', 'w') as f:
thewriter = csv.writer(f)
thewriter.writerow(['Child\'s Age', 'Child speech'])
for root, directory, files in os.walk('/Users/home/Desktop/Childes'):
for f in files:
ffile = os.path.splitext(f)
if ffile[1] == '.xml':
path = os.path.relpath(os.path.join(root, f))
path = '/Users/home/' + path
filename = CHILDESCorpusReader(corpus_root, path)
corpus_participants = filename.participants(path)
corpus_participants_string = str(corpus_participants)
age_string = re.search('(?<=\'age\': \').\w+', corpus_participants_string)
if age_string is not None:
age = age_string.group()
child_speech = filename.sents(path, speaker=['CHI'])
thewriter.writerow([age, child_speech])
else:
print('Not there')
答案 0 :(得分:0)
pd.set_option('max_colwidth', 10)
>>> pd.set_option('max_colwidth', 10)
>>> pd.DataFrame(index=[i for i in range(10)], data={'foo':[['this', 'is', 'a', 'list', 'that', 'is', 'very', 'long'] for i in range(10)]})
foo
0 [this,...
1 [this,...
2 [this,...
3 [this,...
4 [this,...
5 [this,...
6 [this,...
7 [this,...
8 [this,...
9 [this,...