-
Notifications
You must be signed in to change notification settings - Fork 1
/
data_output.py
46 lines (36 loc) · 1.15 KB
/
data_output.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# -*- coding: utf-8 -*-
"""
Created on Wed Jun 26 12:04:16 2019
@author: WentaoZhou
"""
from data_manipulation import procedure
import pandas as pd
import csv
class DataToExternalFile:
"""
write data to specified place
"""
def __init__(self, path):
self.path = path
# functions
def writeDataToCsvWithPanda(self, source, columns):
"""
write data to csv with Pandas
:type source: list
:type columns: list
"""
# convert list to dataframe
df = pd.DataFrame(source, columns=columns)
# write data to external excel file
df.to_excel(self.path, encoding='utf-8', index = False)
def writeDataToCsv(self, source, columns):
"""
write data to csv with python csv module
"""
with open(self.path, 'w', newline='', encoding='utf-8') as csvfile:
# creating a csv writer object
csvwriter = csv.writer(csvfile)
# writing the fields
csvwriter.writerow(columns)
# writing the data rows
csvwriter.writerows(source)