個人昵稱:lxw-pro
個人主頁:歡迎關注 我的主頁
個人感悟: “失敗乃成功之母”,這是不變的道理,在失敗中總結,在失敗中成長,才能成為IT界的一代宗師。
現在呀,雖說已經大面積的使用微信支付、支付寶支付等,可要想微信、支付寶等留有余額,還是離不開我們的存款,存款的話也得有現金,當然,自動取款機還是依舊那麼方便 ,“自己動手,豐衣足食”,那麼,我們的自動取款機又是怎麼知道你存了這麼多,怎麼清楚地知道你的余額的呢,下面我們來康康這所謂的簡易模擬系統叭!
import datetime
class Bank(object):
account_log = []
def __init__(self, name):
self.name = name
def deposit(self, amount): # 存錢
user.balance += amount
self.write_log('存錢', amount)
def withdrawal(self, amount): # 取錢
if amount > user.balance:
print("余額不足")
else:
user.balance -= amount
self.write_log('取錢', amount)
def write_log(self, type, amount): # 寫日志
now = datetime.datetime.now()
ct = now.strftime("%Y-%m-%d %H:%M:%S")
data = [self.name, user.name, ct, type, amount, f"{user.balance:.2f}"]
Bank.account_log.append(data)
class User(object):
def __init__(self, name, balance):
self.name = name
self.balance = balance
def print_log(self):
for item in Bank.account_log:
print(item)
def show_menu():
menu = '''
0: 退出
1: 存款
2: 取款
3: 打印交易信息
'''
print(menu)
bank = Bank("貴陽銀行")
user = User('lxw-pro', 520)
while True:
show_menu()
num = int(input("請輸入菜單編號:"))
if num == 0:
print("退出系統")
break
elif num == 1:
print("存款")
amount = float(input("請輸入存款金額:"))
bank.deposit(amount)
print(f"當前金額是{user.balance:.2f}")
elif num == 2:
print("取款")
amount = float(input("請輸入取款金額:"))
bank.withdrawal(amount)
print(f"當前金額是{user.balance:.2f}")
elif num == 3:
print("查看記錄")
user.print_log()
else:
print("輸入有誤!")
看效果,有點長,故截成兩張圖
————————————————————————————————————————————
# -*- coding = utf-8 -*-
# @Time : 2022/7/29 15:15
# @Author : lxw_pro
# @File : pandas-11 練習.py
# @Software : PyCharm
import pandas as pd
import matplotlib.pyplot as plt
lxw = pd.read_excel("site.xlsx")
print(lxw)
Unnamed: 0 Unnamed: 0.1 create_dt ... yye sku_cost_prc lrl
0 0 1 2016-11-30 ... 8.8 6.77 30.00%
1 1 2 2016-11-30 ... 7.5 5.77 30.00%
2 2 3 2016-11-30 ... 5.0 3.85 30.00%
3 3 4 2016-11-30 ... 19.6 7.54 30.00%
4 4 5 2016-12-02 ... 13.5 10.38 30.00%
.. ... ... ... ... ... ... ...
751 751 752 2016-12-31 ... 1.0 0.77 30.00%
752 752 753 2016-12-31 ... 2.0 1.54 30.00%
753 753 754 2016-12-31 ... 1.0 0.77 30.00%
754 754 755 2016-12-31 ... 7.6 2.92 30.00%
755 755 756 2016-12-31 ... 3.3 2.54 30.00%
[756 rows x 8 columns]
lxw['sku_cost_prc'].plot(kind='kde')
plt.show()
print(-lxw['sku_cost_prc'].diff())
0 NaN
1 1.00
2 1.92
3 -3.69
4 -2.84
...
751 3.13
752 -0.77
753 0.77
754 -2.15
755 0.38
Name: sku_cost_prc, Length: 756, dtype: float64
print(-lxw['sku_cost_prc'].pct_change())
0 NaN
1 0.147710
2 0.332756
3 -0.958442
4 -0.376658
...
751 0.802564
752 -1.000000
753 0.500000
754 -2.792208
755 0.130137
Name: sku_cost_prc, Length: 756, dtype: float64
data = lxw.set_index('create_dt')
print(data)
Unnamed: 0 Unnamed: 0.1 sku_cnt ... yye sku_cost_prc lrl
create_dt ...
2016-11-30 0 1 1.0 ... 8.8 6.77 30.00%
2016-11-30 1 2 1.0 ... 7.5 5.77 30.00%
2016-11-30 2 3 1.0 ... 5.0 3.85 30.00%
2016-11-30 3 4 2.0 ... 19.6 7.54 30.00%
2016-12-02 4 5 1.0 ... 13.5 10.38 30.00%
... ... ... ... ... ... ...
2016-12-31 751 752 1.0 ... 1.0 0.77 30.00%
2016-12-31 752 753 1.0 ... 2.0 1.54 30.00%
2016-12-31 753 754 1.0 ... 1.0 0.77 30.00%
2016-12-31 754 755 2.0 ... 7.6 2.92 30.00%
2016-12-31 755 756 1.0 ... 3.3 2.54 30.00%
[756 rows x 7 columns]
sku_cost_prc
)jz = data['sku_cost_prc'].rolling(10).mean()
print(jz)
create_dt
2016-11-30 NaN
2016-11-30 NaN
2016-11-30 NaN
2016-11-30 NaN
2016-12-02 NaN
...
2016-12-31 5.016
2016-12-31 4.185
2016-12-31 3.500
2016-12-31 2.802
2016-12-31 2.066
Name: sku_cost_prc, Length: 756, dtype: float64
自律的頂端就是享受孤獨!這一年裡,失去,釋懷,成長,完結一半!!
點贊,你的認可是我創作的
動力
!
收藏,你的青睐是我努力的方向
!
評論,你的意見是我進步的財富
!
關注,你的喜歡是我長久的堅持
!
歡迎關注微信公眾號【程序人生6】,一起探討學習哦!!!