-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathpickle_to_Excel.py
66 lines (52 loc) · 1.96 KB
/
pickle_to_Excel.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# -*- coding: utf-8 -*-
"""
功能: 将pickle文件转成便于阅读的Excel文件
Created on Tue Feb 27 16:38:13 2018
@author: Yemon
"""
import pandas as pd
import os
def check_file(file):
if os.path.exists(file):
i = input('{} 已存在! \n继续生成将覆盖原文件,是否继续? [y]/n '.format(file))
else:
i = 'y'
return i
def write_to_Excel():
# Full_stations,City_only,time_point = update
# Full_his,City_his,time_his = his
Full_his = his.full
City_his = his.city
time_his = his.time
Full_stations = update.full
City_only = update.city
xlsx_update = file_update[:-7] + '.xlsx' #更换后缀
xlsx_his = file_his[:-7] + '.xlsx'
i = check_file(xlsx_update)
if i.lower() == 'n':
print('已跳过')
else:
writer = pd.ExcelWriter(xlsx_update)
Full_stations.to_excel(writer, sheet_name ='All Stations')
City_only.to_excel(writer, sheet_name ='City Only')
writer.save()
print('已生成 {} (from {})'.format(xlsx_update,file_update))
i = check_file(xlsx_his)
if i.lower() == 'n':
print('已跳过')
else:
print('Creating...... '.format(xlsx_update))
writer = pd.ExcelWriter(xlsx_his)
Full_his.to_excel(writer, sheet_name ='All Stations')
City_his.to_excel(writer, sheet_name ='City Only')
time_his.to_excel(writer, sheet_name ='Update Log')
writer.save()
print('已生成 {} (from {})'.format(xlsx_his,file_his))
# 待转换的pickle文件名
file_his = '2018-04.pickle'
file_update = 'update.pickle'
his = pd.read_pickle(file_his) # [Full_his, City_his, time_his]
print('{}读取成功'.format(file_his))
update = pd.read_pickle(file_update) # [Full_stations, City_only, time_point]
print('{}读取成功'.format(file_update))
write_to_Excel()