Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
loading text files to pandas
def get_texts(path):
rows_list = []
for idx, label in enumerate(CLASSES):
print(f'working on {path}/{label}')
for fname in (path/f'{label}').glob('*.*'):
dict1 = {}
text = fname.open('r').read()
dict1.update({
'text':text,
'label':idx
})
rows_list.append(dict1)
print(len(rows_list))
df = pd.DataFrame(rows_list)
return df
df = get_texts(PATH/'data_raw')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.