python计算消费总额_python统计一下自己的花费

一直没有在意自己花了多少钱,我卡绑定了电话吧,取钱,支付宝什么的消费,过后都会短信通知,有时间准备统计一下,自己的情况。

然后散点图,柱状图,折线图表示出来。

x轴为时间,y轴为钱数。

占位,等我有时间,把几百条短信整理出来,在作图。

import matplotlib.pyplot as plt

import numpy as np

#x=np.arange(1,13,1)

x=np.linspace(1,13,12,endpoint=True)

print(x)

t2=np.random.randint(700,1000,12)

print(t2)

plt.figure(figsize=(8,6))

plt.plot(x,t2,label="money-time",color="red",linestyle="--",linewidth=1.0)

#得到当前的绘图对象

ax=plt.gca()

ax.set_xlabel("time")

ax.set_ylabel("money")

ax.set_title("the time of spend money")

ax.spines["top"].set_color("none")

ax.spines["right"].set_color("none")

plt.grid(True)

plt.legend()

plt.savefig("suiji.jpg",dpi=230)

plt.show()

suiji.jpg

花费柱状图。

t3=np.random.randint(700,1000,12)

x=np.arange(1,13,1)

x_name=["Jan","feb","march","Apr","may","june","july","Aug","Sept","oct","Nov","Dece"]

plt.bar(x,t3,color="rgb",tick_label=x_name)

ax=plt.gca()

#ax.hist(x_name,t3)

ax.set_xlabel("time")

ax.set_ylabel("money")

ax.set_title("the time of spend money")

ax.spines["top"].set_color("none")

ax.spines["right"].set_color("none")

#plt.grid(True)

#plt.legend()

plt.savefig("zhuzt.jpg",dpi=230)

plt.show()

zhuzt.jpg

上面是随机生成的,这次把手机短信查看 了几十条,不过短信太多了,看的马马虎虎,数据随便做了几十条,我感觉不对。

import numpy as np

import pandas as pd

import matplotlib.pyplot as plt

f=pd.read_excel("my spend.xlsx")

f

结果如下

时间 金钱

0 2016-08-27 10

1 2016-09-04 30

2 2016-09-05 20

3 2016-09-30 185

4 2016-10-12 286

5 2016-11-11 4699

6 2016-11-19 27

7 2016-12-05 12

8 2016-12-12 149

9 2017-02-17 429

10 2017-03-29 900

11 2017-04-29 300

12 2017-05-25 50

13 2017-05-31 30

14 2017-06-28 217

15 2017-08-23 211

16 2017-08-25 5200

17 2017-09-06 210

18 2017-09-16 118

19 2017-09-18 300

20 2017-09-24 50

21 2017-09-27 30

22 2017-09-28 300

23 2017-10-02 300

24 2017-10-09 40

25 2017-10-17 500

26 2017-10-29 310

27 2017-10-31 505

28 2017-11-02 120

29 2017-11-03 300

30 2017-11-05 406

31 2017-11-11 80

32 2017-11-16 46

看一看,其相关数据

sum_money=f.sum()

print("all money:",sum_money)

print(len(f))

print(type(f))

print(f.values)

print(index)

all money: 金钱 16370

dtype: int64

33

[[Timestamp('2016-08-27 00:00:00') 10]

金钱的消费

t=f["金钱"]

print(t[3])

print(type(t))

ax=plt.gca()

ax.set_xlabel("time")

ax.set_ylabel("money")

ax.set_title("the time of spend money")

ax.spines["top"].set_color("none")

ax.spines["right"].set_color("none")

plt.grid(True)

#plt.legend()

t.plot()

plt.grid(True)

plt.savefig("money.jpg",dpi=230)

plt.show()

money.jpg

f=pd.read_excel("my spend.xlsx")

plt.plot(f.时间,f.金钱,color="r")

ax=plt.gca()

ax.set_xlabel("time")

ax.set_ylabel("money")

ax.set_title("the time of spend money")

ax.spines["top"].set_color("none")

ax.spines["right"].set_color("none")

plt.grid(True)

plt.savefig("money-time.jpg",dpi=230)

plt.show()

采用excel读取数据绘制的图像为

money-time.jpg

总的来说失败了,我的数据没有什么用,统计自己的消费也是好玩一下。绘图好像就是这样,没有多少技巧,使用轮子。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值