thesis-anne/CsvHandler.py

28 lines
750 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
class CsvHandler():
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))