forked from shawnbae/project2020
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pandas_csv.py
26 lines (19 loc) · 826 Bytes
/
pandas_csv.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
import os
import pandas as pd
from datetime import datetime, timedelta
import configparser
import glob
config = configparser.ConfigParser()
def to_csv(data):
pathlink = "./"
if not os.path.isdir(pathlink):
os.mkdir(pathlink)
present_date= str(datetime.utcnow() + timedelta(hours = 9))[:10]
if len(glob.glob(pathlink + "/" + present_date + ".csv")) ==1:
cnt= len(pd.read_csv(pathlink + "/" + present_date + ".csv", index_col=0).index)
time_pd = pd.DataFrame(data, index=[cnt])
time_pd.to_csv(pathlink + "/" + present_date + ".csv", mode='a', header= False, encoding='utf-8-sig')
else:
cnt= 0
time_pd = pd.DataFrame(data,index=[cnt])
time_pd.to_csv(pathlink + "/" + present_date + ".csv", mode='a', encoding='utf-8-sig')