pandas versus Excel 学习笔记17(线性回归,数据预测)

这篇博客对比了使用pandas与Excel进行线性回归分析的差异,指出在Python中处理Excel数据时,月份数据可能被误识别为浮点型,需要转换为字符串。文章通过实例展示了如何拟合方程并预测2019年12月的数据,对应的index为35。
摘要由CSDN通过智能技术生成

Excel

python

在excel中month中间有点,python会默认识别为浮点类型的值

因此将其读取为string

sales=pd.read_excel('024/Sales.xlsx',dtype={'Month':str})

 

import pandas as pd
import matplotlib.pyplot as plt
from scipy.stats import linregress
sales=pd.read_excel('024/Sales.xlsx',dtype={'Month':str})
print(sales)
slope,intercept,r,p,std_err=linregress(sales.index,sales.Revenue)
#slope斜率,intercept截距
exp=sales.index*slope+intercept
plt.scatter(sales.index,sales.Revenue)
plt.plot(sales.index,exp,color='orange')
plt.tit
  • 1
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值