thesis-anne/CsvHandler.py

28 lines
735 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):
2018-09-17 12:47:50 +00:00
df = pd.read_csv(csv_file,
sep='|',
header=0,
engine='python',
2018-09-05 12:08:13 +00:00
usecols=[1,2,4], #use only 'Title', 'Text' and 'Label'
2018-09-17 12:47:50 +00:00
decimal='.',
2018-09-05 12:08:13 +00:00
quotechar='\'',
#nrows = 200,
quoting=csv.QUOTE_NONE)
return df
2018-09-17 12:47:50 +00:00
2018-09-05 12:08:13 +00:00
def write_csv(df, file_name):
df.to_csv(file_name, sep='|')
2018-09-26 08:20:56 +00:00
print('# saved {} article(s) in {}'.format(len(df), file_name))