Execl 费用对比 python3 实现
用python 快速的进行运维常规的操作,服务器费用对比
import pandas as pd
import prettytable as pt
from sys import argv
"""
env : python3
pip : pip install pandas
pip install prettytable
// 对比 csv
"""
def pdread_csv(filename):
df = pd.read_csv(filename, encoding="utf-8")
lists = list(df)[1:]
values = list(df.loc[0].values)[1:]
dicts = dict(zip(lists, values))
return lists, values, dicts
if __name__ == '__main__':
"""
a = 上上周
b = 上周
"""
a = pdread_csv(argv[1])
b = pdread_csv(argv[2])
falses_tb = pt.PrettyTable()
tures_tb = pt.PrettyTable()
tures_tb.field_names = ["ture 服务名称", "上周", '上上周', "上周 / 变动"]
falses_tb.field_names = ["false 服务名称", '数值', '时间']
all_ture = [x for x in a[0] if x in b[0]]
all_false = [y for y in (a[0] + b[0]) if y not in all_ture]
for i in all_ture:
tblist = [i, int(a[2][i]), int(b[2][i]), int(a[2][i] - b[2][i])]
tures_tb.add_row(tblist)
for i in all_false:
if i in a[0]:
falses_tb.add_row([i, int(a[2][i]), '上周'])
elif i in b[0]:
falses_tb.add_row([i, int(b[2][i]), '上上周'])
print(tures_tb)
print()
print(falses_tb)
input('Are you ok / Enter')
不断学习