thesis-anne/CsvHandler.py

28 lines
748 B
Python
Raw Normal View History

2018-09-05 12:08:13 +00:00
'''
Csv Handler
===========
CsvHandler writes articles' information to csv file and reads it.
'''
import csv
import pandas as pd
2018-09-10 08:38:24 +00:00
class CsvHandler:
2018-09-05 12:08:13 +00:00
def read_csv(csv_file):
df = pd.read_csv(csv_file,
sep='|',
header=0,
engine='python',
usecols=[1,2,4], #use only 'Title', 'Text' and 'Label'
decimal='.',
quotechar='\'',
#nrows = 200,
quoting=csv.QUOTE_NONE)
return df
def write_csv(df, file_name):
df.to_csv(file_name, sep='|')
print('### saved {} articles in {}'.format(len(df), file_name))