데이터 링크를 게시 해 주셔서 감사합니다. 공개적으로 사용할 수 있다면 처음에는 그렇게하는 것이 도움이됩니다. 전체 데이터 세트에서이를 실행했습니다. 괜찮은 노트북에서 2 초 정도 걸렸습니다. 이 게시물에서
import numpy as np
import pandas as pd
with open('rfa_all.NL-SEPARATED.txt', 'r') as f:
data = f.readlines()
# create a dictionary with keys and lists.
# if you don't set the values as lists, you get an error.
d = {'SRC': [], 'TGT': [], 'VOT': [], 'RES': [], 'YEA': [], 'DAT': [], 'TXT': []}
for line in data: # go through file line by line
if line != '\n': # skip new line characters
line = line.replace('\n', '') # get rid of '\n' in all fields
key, val = line.split(':', 1) # take the first 2 tokens from the split statement
d[key].append(val)
df = pd.DataFrame(d)
df
광범위한 도움 : https://stackoverflow.com/a/26644245/6672746
내가 이것을 설정하는 더 빠른 방법이 있는지,하지만 난이 일 것이라 생각합니다.
제목 3 데이터는 다음 줄로 이동할 수 있습니다. – harry
"blah"문자열이있는 텍스트 파일을 문자 그대로로드하지 않는 한 입력 데이터의 모양을 더 잘 나타내야합니다. 예 : 값에 문자열'split' 메서드를 사용하여 목록으로 변환 할 수 있습니까? –
안녕하세요, 데이터는 [여기] (https://snap.stanford.edu/data/wiki-RfA.html)의 zip 파일입니다. – harry