28 lines
748 B
Python
28 lines
748 B
Python
'''
|
|
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)) |